如何在jquery中将密码转换为md5? [英] How to convert password into md5 in jquery?
问题描述
其实我正在创建changepassword页面。这是我检查旧密码与现有密码匹配的功能。并且该密码存储在数据库中的MD5中,因此我想首先在MD5中转换该密码,之后我可以检查该密码。
这是代码。
Actually i am creating changepassword page. and this is my function of checking old password is match with the existing password or not. And that password is stored in MD5 in database so i want to first convert that password in MD5 and after that i can check that password. Here is the code.
function fnIsValidOldPassword()
{
var oldPassword = "";
var objUser = new Object();
objUser.UserID = <?php echo $_SESSION['UserId'] ?>;
$.ajax({
type: "POST",
url: "db.php?GetUser",
data: {data:objUser},
async:false,
dataType:"json",
success: function(response)
{
if(response.IsError)
alert(response.ErrorMessage);
else
oldPassword = response.Records[0].Password;
},
error:function(message)
{
alert("Error: " + message);
}
});
if($.md5($("#txtOldPassword").val())) != oldPassword)
^^ //here it shows error. that md5 is not a function.
{
$("#errorPassword")[0].innerHTML = "Wrong Old Password.";
$("#txtOldPassword").removeClass("successTextBox").addClass("errorTextBox");
return false;
}
$("#txtOldPassword").removeClass("errorTextBox").addClass("successTextBox");
$("#errorPassword")[0].innerHTML = "";
return true;
}
md5不是jquery中的函数,那么如何在md5中转换密码。
md5 is not a function in jquery then how to convert the password in md5.
推荐答案
jQuery没有提供字符串md5的方法。所以你需要使用一些外部脚本。有一个名为jQuery MD5的插件。它为您提供了许多实现md5的方法。其中很少是
jQuery doesnt have a method to provide the md5 of a string. So you need to use some external script. There is a plugin called jQuery MD5. and it gives you number of methods to achieve md5. Few of those are
创建(十六进制编码)给定字符串值的MD5哈希:
Create (hex-encoded) MD5 hash of a given string value:
var md5 = $.md5('value');
创建(十六进制编码)给定字符串值和密钥的HMAC-MD5哈希:
Create (hex-encoded) HMAC-MD5 hash of a given string value and key:
var md5 = $.md5('value', 'key');
创建给定字符串值的原始MD5哈希:
Create raw MD5 hash of a given string value:
var md5 = $.md5('value', null, true);
创建给定字符串值和密钥的原始HMAC-MD5哈希:
Create raw HMAC-MD5 hash of a given string value and key:
var md5 = $.md5('value', 'key', true);
这可能会做你想要的...在这里查看代码片段。 jQuery MD5
This might do what you want... Check the snippet here. jQuery MD5
这篇关于如何在jquery中将密码转换为md5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!