Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP-在提交页面上重新输入密码_Php_Validation_Cakephp_Passwords - Fatal编程技术网

CakePHP-在提交页面上重新输入密码

CakePHP-在提交页面上重新输入密码,php,validation,cakephp,passwords,Php,Validation,Cakephp,Passwords,我是CakePHP新手,需要提示(管理员)用户在提交页面上重新输入密码。页面,其中需要添加验证用于修改子用户的信息。我曾试图在Stack Overflow和其他论坛上找到解决方案,但没有成功 详情如下: 我们在edit.ctp上有3个按钮,通过更改子用户在用户表中的状态,“启用”、“禁用”和“删除”子用户 echo $this->Form->button('Enable', array('onclick'=> 'change_status(1);'));

我是CakePHP新手,需要提示(管理员)用户在提交页面上重新输入密码。页面,其中需要添加验证用于修改子用户的信息。我曾试图在Stack Overflow和其他论坛上找到解决方案,但没有成功

详情如下:

我们在edit.ctp上有3个按钮,通过更改子用户在用户表中的状态,“启用”、“禁用”和“删除”子用户

 echo $this->Form->button('Enable', array('onclick'=> 'change_status(1);'));

            echo $this->Form->button('Disable', array('onclick'=> 'change_status(0);'));

            echo $this->Form->button('Delete', array('onclick'=> 'change_status(2);'));
有一个隐藏的文本字段绑定到Users表的status字段。它可以有3个值:1(已启用)、0(已禁用)和2(已删除)。 PS:由于某些原因,我们无法删除用户的记录,因此依赖这些“状态”。当用户单击3个按钮中的任何一个时,此字段将更新

echo $this->Form->hidden('user.status', array('label' => false, 'type' => 'text' , 'value'=> $user["User"]["status"], 'id' => 'status_id')); 
JavaScript函数

功能更改\u状态(状态){
document.getElementById(“status_id”).value=status;
}

现在,当用户单击3个按钮中的任何一个时,我们需要提示用户重新输入密码。如果密码与登录密码不匹配,则不应允许他们执行该操作。

我假设您的数据库中有users表(否则您可以修改自己)。在用户控制器中

public function checkPassword($userid,$password)
{
    $hashed_pwd = $this->User->passwordHash($password); // call passwordHash function in User.php model
    $condition = array('User.id'=>$userid,'User.password'=>$hashed_pwd);

    if($this->User->hasAny($condition)) // check if password with that userid exists in users table
    {
        $output['status'] = 1; // give access
    } else {
        $output['status'] = 0
    }

    $this->set('output'=>$output);

}
在用户模型中

public function passwordHash($password) {
    return   AuthComponent::password($password);

}

在您的视图中,您可以检查控制器中编写的checkPassword函数给出的响应

您需要显示您的(特定)代码,并询问与代码相关的特定问题,以使其成为stackoverflow的主题。另外请注意,您提出的问题(概念上)不是CakePHP特有的。谢谢您的回答。我已经编辑了这个问题。我希望现在已经很清楚了,我一直在尝试调用函数,但是得到了缺少参数2的错误。第一个参数被传递(我可以通过函数checkPassword在屏幕上打印),但第二个参数没有$参数=$userId.'/'.$userPassword;$result=$this->requestAction('/users/checkPassword/'.$parameters);错误:警告(2):UsersController::checkPassword()缺少参数2[APP/controllers/users\u controller.php,第118行]如果是,请从checkPassword函数中删除第2个参数,并将密码设置为:$password=$this->request->data['User']['password']//$从该函数分配给表单密码的密码。
public function passwordHash($password) {
    return   AuthComponent::password($password);

}