-3

I want to change the password encryption from bcrypt to encrypt though the password successfully Updated, but I can't login using the new password.

public function updatePassword(Request $request)
{
    $user = User::find($request->id);
    $user->password = encrypt($request->newPassword);
    $user->save();
}
Marky
  • 55
  • 1
  • 2
  • 11
  • Please make sure if the part "bcrypt to encrypt" is correct. Encrypt is a concept and not some method. – Vinayak Sarawagi Jun 18 '20 at 02:50
  • I am encrypting the `newPassword` – Marky Jun 18 '20 at 03:05
  • 1
    dude bcrypt and encrypt are not same, bcrypt is hashing and could not back to the plain text and encrypt is encoding information which could be decrtypt and back to the plain text. Larevel is using verify password which using hashing not encryption – Kelvin Jun 18 '20 at 03:10
  • @Kelvin Okay, I am new to Laravel dude. How can I achieve this? Since I want to show also their password, so maybe encrypt is I want to use. right? – Marky Jun 18 '20 at 03:12

2 Answers2

0

Please try it:

/**
 * Handle a login request to the application.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse
 *
 * @throws \Illuminate\Validation\ValidationException
 */
public function login(Request $request)
{
    $decrypted = $request->input('password'); 
    $user      = User::where('email', $request->input('email'))->first();

    if ($user) {
        if (Crypt::decryptString($user->password) === $decrypted) {
            Auth::login($user);

            return $this->sendLoginResponse($request);
        }
    }

    return $this->sendFailedLoginResponse($request);
}
Thai Nguyen Hung
  • 1,154
  • 5
  • 13
0

As you mention you want to save user password, which you can show their password i recommend you should take a look here because you dont need to know the user's password in case for the security reason

But you could able to make User Auth using encrypt which you need to compare the input password and encrypt it then compare to password from database

in you login function

function login(){
    $password = request('password'); 
    $email = request('email');
    $user = User::where('emai',$email)->first();
    if(encrypt($password) === $user->password){
        Auth::login($user); //for user auth session
        //login success
    }else{
        //failed to login
    }
}
Kelvin
  • 1,004
  • 1
  • 10
  • 32