Laravel 4:自定义登录和检查密码

Orv*_*vyl 1 php mysql laravel laravel-4 laravel-3

我想定制我的登录界面,在laravel 4,其中username要么是他username还是email那么我所做的是:

public static function custom_login($uname,$pwd)
{
    $res = DB::select("select * from users where (username = ? or email = ?) and password = ? and active = 1",array($uname,$uname,$pwd));
            return $res;
}
Run Code Online (Sandbox Code Playgroud)

现在,我们都知道密码是哈希的,所以你无法使用password = ?.如果密码正确,我怎么检查密码?

And*_*yco 8

我同意这里的人的原则,但我会使用Eloqunet,以防表格名称将来会改变.

$user = User::whereRaw('email = ? OR username = ?', array('value', 'value'))->first();

if ( ! $user) {
    return false;
}

if (Hash::check('password', $user->password)) {
    // The passwords match, log in the user
    Auth::loginUsingId( $user->id );
}
Run Code Online (Sandbox Code Playgroud)

我动态编写代码,很抱歉,如果出现语法错误.