Ruby on Rails 5.2 - ActiveModel::SecurePassword::InstanceMethodsOnActivation

मॉड्यूल ActiveModel :: SecurePassword :: InstanceMethodsOnActivation




ruby

मॉड्यूल ActiveModel :: SecurePassword :: InstanceMethodsOnActivation

गुण

पासवर्ड [R]

सार्वजनिक प्रवृत्ति के तरीके

प्रमाणीकृत करें (unencrypted_password) स्रोत दिखाएं
# File activemodel/lib/active_model/secure_password.rb, line 96
def authenticate(unencrypted_password)
  BCrypt::Password.new(password_digest).is_password?(unencrypted_password) && self
end

पासवर्ड सही होने पर self वापस आ जाता है, अन्यथा false

class User < ActiveRecord::Base
  has_secure_password validations: false
end

user = User.new(name: 'david', password: 'mUc3m00RsqyRe')
user.save
user.authenticate('notright')      # => false
user.authenticate('mUc3m00RsqyRe') # => user
पासवर्ड = (unencrypted_password) स्रोत दिखाएं
# File activemodel/lib/active_model/secure_password.rb, line 114
def password=(unencrypted_password)
  if unencrypted_password.nil?
    self.password_digest = nil
  elsif !unencrypted_password.empty?
    @password = unencrypted_password
    cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
    self.password_digest = BCrypt::Password.create(unencrypted_password, cost: cost)
  end
end

पासवर्ड को पासवर्ड_डिगस्ट विशेषता में एन्क्रिप्ट करता है, केवल तभी जब नया पासवर्ड खाली न हो।

class User < ActiveRecord::Base
  has_secure_password validations: false
end

user = User.new
user.password = nil
user.password_digest # => nil
user.password = 'mUc3m00RsqyRe'
user.password_digest # => "$2a$10$4LEA7r4YmNHtvlAvHhsYAeZmk/xeUVtMTYqwIvYY76EW5GUqDiP4."
password_confirmation = (unencrypted_password) स्रोत दिखाएँ
# File activemodel/lib/active_model/secure_password.rb, line 124
def password_confirmation=(unencrypted_password)
  @password_confirmation = unencrypted_password
end