php - Laravel 中的用户名/密码认证规则

标签 php validation laravel laravel-4

目前,当用户登录到我的 Laravel 应用程序时,我使用以下规则...

// Validation rules
$rules = array(
    'email' => 'required|email|exists:users,email',
    'password' => 'required'
);

我正在寻找的是用于检查用户密码的验证规则。

最佳答案

来自 docs :

if (Auth::attempt(array('email' => $email, 'password' => $password))) {
    return Redirect::intended('dashboard');
}

例子:

$userdata = array(
    'email'    => Input::get('email'),
    'password' => Input::get('password')
);

$rules = array(
    'email' => 'required|email|exists:users,email',
    'password' => 'required'
);

// Validate the inputs.
$validator = Validator::make($userdata, $rules);

// Check if the form validates with success.
if ($validator->passes()) {
    // Try to log the user in.
    if (Auth::attempt($userdata)) {
        // Redirect to homepage
        return Redirect::to('')->with('success', 'You have logged in successfully');
    } else {
        // Redirect to the login page.
        return Redirect::to('login')->withErrors(array('password' => 'Password invalid'))->withInput(Input::except('password'));
    }
}

关于php - Laravel 中的用户名/密码认证规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16857820/

相关文章:

php - 连接到 ubuntu 服务器中的 mysql 数据库

php - 函数中的可变长度引用参数列表

ruby - 验证关联模型的特定属性

html - 检查浏览器是否内置 HTML5 表单验证?

Laravel关系: A division has many ranks,一个等级有1个分区,一个用户只有1个等级

php - 在 Codeigniter 中使用 LIMIT 选择

javascript - 全日历功能中的 AJAX

python - Django:显示管理员验证错误的自定义错误消息

unit-testing - Laravel 5.1 中的模拟请求用于(实际)单元测试

php - 每个路由在共享主机上都显示 404 消息