php - How to get encrypted password value in laravel? -
i trying change password of user need check old password of user match value getting html "oldpass" text box. if existing password value , "oldpass" value matches new password updated in database.the password value getting database encrypted.
$userpass = user::where('id', '=', session::get('userid'))->get(array('password')); problem $userpass returns null value .
here code:
$oldpass = hash::make(input::get('oldpass'));//getting password html form $userpass = user::where('id', '=', session::get('userid'))->get(array('password'));//getting password value database users table if ($oldpass === $userpass) { user::where('id', '=', session::get('userid')) ->update(array( 'password' => hash::make(input::get('newpass')) )); } else { return view::make('changepass.changepass') ->with('errormessage', 'password not match'); }
there 2 main problems here.
on 1 hand,
$userpass
returning null becauseget()
not appropiate function fecth column. can use pluck (see query builder docs)anyway can call attribute once fetch user like:
$userpass = user::find(session::get('userid'))->password;
you trying compare hashed password plain password. laravel uses guard default manage user authentication , guard uses
hash::make
store it. should compare hashes with:hash::check($oldpass, $userpass)
you check guard user credentials correct auth::validate($credentials)
(see laravel security) , change password like:
if(auth::validate('id' => session::get('userid'), 'password' => input::get('oldpass'))){ //assuming user authenticated before. if not use auth::attempt instead of validate auth::user()->password = hash::make(input::get('newpass')); } else { return view::make('changepass.changepass') ->with('errormessage', 'password not match'); }
Comments
Post a Comment