OmniAuth + Identity Forgot Password

I am developing a Rails 3.0 application and using OmniAuth + Identity to authenticate registration. I implemented a User model bound to an Identity model through a foreign key, and everything works fine. Now I want to implement the forgotten password function.

Given the user's email, I want to send them an email with a link to reset their password. The email contains a random sixth line associated with the user.

Now, how do I reset the Identity user password?

In the Identity database table, it is stored as password_digest. Can I just rewrite this?

+6
source share
2 answers

So it turns out that it's simple. Just rewrite the existing digest_password in the Identity table. Use the BCrypt library to create password_digest:

require 'bcrypt' ... class UsersController < ApplicationController ... def update @user = User.find(params[:id]) ... user_identity = Identity.find_by_email(@user.email) unencrypted_password = params[:user][:password].to_s password_digest = BCrypt::Password.create(unencrypted_password) user_identity.password_digest = password_digest; user_identity.save! end end 
+4
source

Do it:

 @identity = Identity.find(1) @identity.password = "newpassword" @identity.password_confirmation = "newpassword" @identity.save 

In omniauth-identity issue , wdspkr says:

Once you realize that omniauth-identity uses ActiveModel, SecurePassword is really easy to solve this problem. Instead of setting password_digest, you just set the password and password_ confirmation and update.

+10
source

Source: https://habr.com/ru/post/912273/


All Articles