dtdfl62844 2015-02-03 11:33
浏览 343
已采纳

检查旧密码和新密码的规则

I am checking for Old Password and New Password with Confirmation Password.

Here i want to check with whether OldPassword and New Password should not be same.

How can i do this ?

Here is my Rule :

   public static $rulespwd = array('OldPassword' => 'required|pwdvalidation',
        'NewPassword' => 'required|confirmed|min:1|max:10',
        'NewPassword_confirmation' => 'required',
        );

Here is my controller code for the validation :

$PasswordData = Input::all();
        Validator::extend('pwdvalidation', function($field, $value, $parameters)
        {
            return Hash::check($value, Auth::user()->password);
        });

        $messages = array('pwdvalidation' => 'The Old Password is Incorrect');

        $validator = Validator::make($PasswordData, User::$rulespwd, $messages);
        if ($validator->passes()) 
        {
            $user = User::find(Auth::user()->id);
            $user->password = Input::get('NewPassword');
            $user->save();
            return Redirect::to('changepassword')->with('Messages', 'The Password Information was Updated');
        }

Note : I am using model for validation rule.. How can i do this in model ??

  • 写回答

1条回答 默认 最新

  • dongzhangji4824 2015-02-03 11:35
    关注

    Just use the different validation rule - as described in the Laravel docs

    public static $rulespwd = array('OldPassword' => 'required|pwdvalidation',
        'NewPassword' => 'required|confirmed|min:6|max:50|different:OldPassword',
        'NewPassword_confirmation' => 'required',
        );
    

    Also - why are you limiting a password to 10 chars? That is silly - there is no reason to limit it at all. All your are doing is reducing your application security.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害