Can the Laravel authentication system use an existing database?

advertisements

I am developing an admin panel in PHP with the Laravel framework. Some of the front end is already made. With that said, the database and user table is already created and has content. Is there any way to use my existing database and table with the Laravel Auth class?

My database has it's own way of encrypting passwords - can Laravel adapt to that?


You can do auth directly, if you need:

$user = User::where('email', Input::get('email'))->first();

if( $user && $user->password == md5(Input::get('password')) )
{
    Auth::login($user); /// will log the user in for you

    return Redirect::intended('dashboard');
}
else
{
   /// User not found or wrong password
}

Note that passwords hashed by Laravel are really secure and those hashed by, let's say, MySQL, are the opposite. So you could convert your passwords every time your user logs, without asking him to do so:

$password = Input::get('password');

$email = Input::get('email');

if (Auth::attempt(array('email' => $email, 'password' => $password)))
{
    return Redirect::intended('dashboard');
}
else
if( $user && $user->password == md5($password) )
{
    Auth::user()->password = Hash::make($password);

    Auth::user()->save();

    return Redirect::intended('dashboard');
}
else
{
    /// User not found or wrong password
}