Last active
August 29, 2015 13:56
-
-
Save pedro-vasconcelos/9187511 to your computer and use it in GitHub Desktop.
Migrate users from MD5 Hash system to Laravel without ask the users to change the password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Try to log the user in. | |
if (Auth::attempt($userdata)) | |
{ | |
// Redirect to homepage | |
return Redirect::to('')->with('success', 'You have logged in successfully'); | |
} | |
else | |
{ | |
$user = User::where('username','=',$userdata['username'])->first(); | |
if(isset($user)) { | |
if($user->password == md5($userdata['username']."\n".$userdata['password'])) { // If their password is still MD5 | |
$user->password = Hash::make($userdata['password']); // Convert to new format | |
$user->save(); | |
Auth::login($userdata['username']); | |
}else{ | |
// Redirect to the login page. | |
return Redirect::to('login')->withErrors(array('password' => 'Password invalid'))->withInput(Input::except('password')); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment