Converting plain password in database to Laravel encrypted password

前端 未结 2 1134
走了就别回头了
走了就别回头了 2021-01-27 11:00

I have a table called \"users\" where I have username and password from my users.

The passwords are in plain text. Now I\'ve created a new site with Laravel 6.0 and Auth

2条回答
  •  梦谈多话
    2021-01-27 11:37

    The Laravel Hash facade provides secure Bcrypt and Argon2 hashing for storing user passwords.

    $password = Hash::make('plain-text-password');
    

    The bcrypt function hashes the given value using Bcrypt. You may use it as an alternative to the Hash facade:

    $password = bcrypt('plain-text-password');
    

    How can I get the "salt" from my Auth and also a tools to get the encrypted password from my plain password and "salt".

    Verifying A Password Against A Hash

    The check method allows you to verify that a given plain-text string corresponds to a given hash.

    if (Hash::check('plain-text-password', $hashedPassword)) {
        // The passwords match...
    }
    

    Update

    You can use Command or make a route to change "plain-text" password for existing customers.

    Create command app/Console/Commands/ChangePassword.php

    password)) {
                    $user->password = Hash::make($user->password);
                    $user->save();
                }
            }
    
            $this->info('Done..');
        }
    }
    
    Usage :
    php artisan change-password
    

    After run command, you can try login via Auth::routes() routes.


    Or Manually Authenticating Users

    if (Auth::attempt($credentials)) {
        // Authentication passed...
    } 
    

提交回复
热议问题