ruby-on-rails – 设计:使用两个可能的加密密码登录
发布时间:2020-12-17 07:10:22 所属栏目:百科 来源:网络整理
导读:我的应用程序与Devise gem一起使用进行身份验证,但我希望使用两个可能的加密密码自定义它,因为我以前的应用程序使用了MD5.我的用户表中有两个字段:encrypted_pa??ssword和encrypted_old_password(我已经创建),我想检查是否存在值encrypted_pa??ssword以及发
我的应用程序与Devise gem一起使用进行身份验证,但我希望使用两个可能的加密密码自定义它,因为我以前的应用程序使用了MD5.我的用户表中有两个字段:encrypted_pa??ssword和encrypted_old_password(我已经创建),我想检查是否存在值encrypted_pa??ssword以及发送的密码是否与一个集匹配,否则,检查它是否与MD5一致,如果为true,然后替换值encrypted_pa??ssword.
我是怎么做到的 解决方法
我不知道我的回答是否很奇特,但对我有用.我希望有人可以改善我的所作所为.
class SessionsController < Devise::SessionsController def create recover_old_password unless user_signed_in? resource = warden.authenticate! auth_options set_flash_message(:notice,:signed_in) if is_navigational_format? sign_in resource_name,resource respond_with resource,:location => after_sign_in_path_for(resource) end def recover_old_password email = params[:user]['email'] pass = Digest::MD5.hexdigest params[:user]['password'] @user = User.find_by_email_and_encrypted_old_password(email,pass) if @user.blank? resource = warden.authenticate! auth_options respond_with resource,:location => after_sign_in_path_for(resource) elsif if !@user.encrypted_password.nil? @user.encrypted_password = BCrypt::Password.create params[:user]['password'] @user.save create end end end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |