Skip to content

Instantly share code, notes, and snippets.

@pedro-vasconcelos
Last active August 29, 2015 13:56
Show Gist options
  • Save pedro-vasconcelos/9187511 to your computer and use it in GitHub Desktop.
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
<?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