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.

  1. on 1 hand, $userpass returning null because get() 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;

  2. 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

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -