roysathome.net/auth/cryptography.rb

20 lines
448 B
Ruby
Raw Normal View History

2023-12-11 20:56:09 +00:00
require 'bcrypt'
2023-12-13 16:02:09 +00:00
require 'securerandom'
2023-12-11 20:56:09 +00:00
2023-12-12 22:52:36 +00:00
def create_password_for_user(password)
return BCrypt::Password.create(password)
end
def check_password_for_user(user_id, entered_password)
hashed_password = get_user_hashed_password(user_id)
if BCrypt::Password.new(hashed_password) == entered_password
return true
else
return false
end
2023-12-13 16:02:09 +00:00
end
def generate_random_string(length)
SecureRandom.urlsafe_base64(length)
2023-12-14 17:25:02 +00:00
end