更改新密码时如何验证旧密码

时间:2014-10-09 05:33:13

标签: jquery

我有一个用于编辑用户帐户的表单,在那里我给输入字段包含新密码和旧密码。如果未填写新密码字段,则将存储数据,如果必须填写旧密码字段中填写的新密码字段,那么我该如何提供验证?新密码不等于旧密码。

这是我的代码:

<div class="form-group">
     <label class="control-label">Current Password</label>
     <input type="password" name="currentPassword" class="form-control">
</div>
<div class="form-group">
    <label class="control-label">New Password</label><input type="password" name="newPassword" id="newPassword" class="form-control">
</div>

有什么建议吗?

2 个答案:

答案 0 :(得分:1)

Considering you HTML to be something like this:-

<div class="form-group">
     <label class="control-label">Current Password</label>
     <input id="oldpassword" type="password" name="currentPassword" class="form-control">
</div>
<div class="form-group">
    <label class="control-label">New Password</label>
    <input type="password" name="newPassword" id="newPassword" class="form-control">
</div>

Javascript Code:-

if ($.trim($('#newPassword').val()) != "" && $.trim($(#oldpassword').val()) == "")
 { 
     return false; // Display error message
 }
else if  ($.trim($('#newPassword').val()) != "" && $.trim($(#oldpassword').val()) != "")
{
    if ($.trim($('#newPassword').val()) != $.trim($(#old`enter code here`password').val())
     {
        //Show error message that password doesn't match
     }
}

答案 1 :(得分:0)

请按照以下HTML&amp;使用Jquery远程验证的Javascript代码

curl -X PATCH https://api.godaddy.com/v1/domains/{domain}/records \
  -H 'Authorization: sso-key xyz:xyz' \
  -H 'Content-Type: application/json' \
  --data '[{"type": "A","name": "blnk1","data": "192.1.2.3","ttl": 3600}]'

➜  ~ dig blnk.{domain}
;; ANSWER SECTION:
blnk.{domain}. 3599 IN  A   192.1.2.3