php - 将确认密码与散列密码进行比较 |拉维尔 4

标签 php mysql hash laravel laravel-4

我正在尝试获取确认密码以对付我表单中的密码字段。我检查了 Validator 方法,它们似乎都运行良好。但是,当我尝试确认密码时,每次他们必须匹配时我都会收到一条错误消息……我挠头只能确定这是因为在通过验证之前对它们进行了哈希处理。我不确定如何解决这个问题,因为在将它们输入数据库之前需要对其进行哈希处理。有什么想法吗?

getSignUp Controller

        public function getSignUp() {
            $userdata = array(
                'email' => Input::get('email'),
                'password' => Hash::make(Input::get('password')),
                'confirm_password' => Hash::make(Input::get('confirm_password')),
                'user_zip_code' => Input::get('user_zip_code')         
            );

            $rules = array(
                'email' => 'required|email|unique:users,email',
                'password' => 'required|min:5',
                'confirm_password' => 'required|same:password',
                'user_zip_code' => 'required'
            );

            $validation = Validator::make($userdata, $rules);

            if($validation->fails()){
                return Redirect::to('signup')->withErrors($validation)->withInput();
            } 

            $user = new User($userdata);
            $user->save();

            return Redirect::to('login');
    }

如果需要更多代码,请告诉我。我只是让 withErrors 转到注册页面的 Blade 模板

最佳答案

不要将哈希密码传递给验证器。在保存之前对其进行哈希处理:

public function getSignUp() {
    $userdata = array(
        'email' => Input::get('email'),
        'password' => Input::get('password'),
        'confirm_password' => Input::get('confirm_password'),
        'user_zip_code' => Input::get('user_zip_code')         
    );

    $rules = ...

    $validation = Validator::make($userdata, $rules);

    if($validation->fails()){
        return Redirect::to('signup')->withErrors($validation)->withInput();
    } 

    $userdata['password'] = Hash::make($userdata['password']);

    $user = new User($userdata);
    $user->save();

    return Redirect::to('login');
}

关于php - 将确认密码与散列密码进行比较 |拉维尔 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18425370/

相关文章:

php - 在 symfony 中使用 PrePersist

javascript - $.get 将数字转换为字符串

mysql 在两列上使用 FOREIGN KEY

ruby - 如何在不转换为数组的情况下按 Ruby 中的数值对哈希进行排序?

java - sun.misc 包在 java 中仍然可用吗?

php - MYSQL - 返回行数组的 INNER JOIN

php - 在 codeigniter 中我如何检查更新?

php - 在一定时间(30 秒)后检查 mysql 数据库中的值后运行函数

php - _POST 方法返回 ???当请求utf8字符时

c - 从文件中读取换行符分隔的项目