java⽤户名和密码明⽂传输,JavaScript基础教程⽤户登录明⽂
传输密码问题如何解决...
本篇教程介绍了JavaScript基础教程 ⽤户登录明⽂传输密码问题如何解决,希望阅读本篇⽂章以后⼤家有所收获,帮助⼤家对JavaScript 的理解更加深⼊。
<
⽤户登录页⾯,获取到⽤户密码,⽤MD5加密,然后进⾏传输,服务器端获取的是⼀个加密过的密码。然后把从数据库⾥⾯获取的密码也⽤MD5加密,然后⽐较,验证登录。
为什么⽤这种⽅法呢,当时想了2个⽅案,⼀个是换成https服务器,然后购买⼀个证书(所有需要⽤钱的都要⼀层⼀层审批,我不知道审批下来后,我还有想做不),另⼀个就是今天要说的,javascript+ Java+md5
---------------------------------------------------------------------------------------------------前端------------------------------------------------------------------------------------------------------------
//MD5加密
function encryptionPassword(){
var ElementById("cpassword").value;
var hash=MD5(hpassword)
}
MD5⽅法的md5.js 代码最后给出,有点多
---------------------------------------------------------------------------------------------------后台------------------------------------------------------------------------------------------------------------
把从数据库获得的密码⽤MD5加密
password.Password()).substring(22,32))
StringUtil⼯具类中具体代码如下:
/**
* MD5加密
* @修改时间:2015-06-08
* @修改作者:Wangj
*
*/
public synchronized static final String getMD5Str(String str) {
if (null == str) {
str = "";
}
String MD5Str = "";
try {
/
/ JDK 6 ⽀持以下6种消息摘要算法,不区分⼤⼩写
// md5,sha(sha-1),md2,sha-256,sha-384,sha-512
MessageDigest messageDigest = Instance("MD5");
messageDigest.Bytes());
byte b[] = messageDigest.digest();
int i;
StringBuilder builder = new StringBuilder(32);
for (int offset = 0; offset
i = b[offset];
if (i
i += 256;
if (i
builder.append("0");
builder.HexString(i));
}
MD5Str = String();
// LogUtil.println("result: " + String());// 32位的加密
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return MD5Str;
}
最后是mds.js的代码
---------------------------------------------------------------------------------------------------md5.js--------------------------------------------------------------------------------------------------------
(function UMD(name, context, definition) {
if (typeof module !== "undefined" && ports) {
} else if (typeof define === "function" && define.amd) {
define(definition);
} else {
context[name] = definition(name, context);
}
})
("md5",
this,
function DEF(name, context) {
"use strict";
var old_public_api = (context || {})[name];
function md5_func(text) {
return hex_md5(text);
}
;
//计算MD5算法
var hexcase = 0;
function hex_md5(a) {
if (a == "")
return a;
return rstr2hex(rstr_md5(str2rstr_utf8(a)))
}
;
function hex_hmac_md5(a, b) {
return rstr2hex(rstr_hmac_md5(str2rstr_utf8(a),
str2rstr_utf8(b)))
}
;
java基础教程第三版pdf
function md5_vm_test() {
return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72" }
;
function rstr_md5(a) {
return binl2rstr(binl_md5(rstr2binl(a), a.length * 8))
}
;
function rstr_hmac_md5(c, f) {
var e = rstr2binl(c);
if (e.length > 16) {
e = binl_md5(e, c.length * 8)
}
var a = Array(16), d = Array(16);
for ( var b = 0; b
a[b] = e[b] ^ 909522486;
d[b] = e[b] ^ 1549556828
}
var g = binl_at(rstr2binl(f)), 512 + f.length * 8);
return binl2rstr(binl_at(g), 512 + 128))
}
;
function rstr2hex(c) {
try {
hexcase
} catch (g) {
hexcase = 0
}
var f = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; var b = "";
var a;
for ( var d = 0; d
a = c.charCodeAt(d);
b += f.charAt((a >>> 4) & 15) + f.charAt(a & 15)
}
return b
}
;
function str2rstr_utf8(c) {
var b = "";
var d = -1;
var a, e;
while (++d
a = c.charCodeAt(d);
e = d + 1
if (55296 <= a && a <= 56319 && 56320 <= e
&& e <= 57343) {
a = 65536 + ((a & 1023) <
d++
}
if (a <= 127) {
b += String.fromCharCode(a)
} else {
if (a <= 2047) {
b += String.fromCharCode(
192 | ((a >>> 6) & 31), 128 | (a & 63)) } else {
if (a <= 65535) {
b += String.fromCharCode(
224 | ((a >>> 12) & 15),
128 | ((a >>> 6) & 63),
128 | (a & 63))
} else {
if (a <= 2097151) {
b += String.fromCharCode(
240 | ((a >>> 18) & 7),
128 | ((a >>> 12) & 63),
128 | ((a >>> 6) & 63),
128 | (a & 63))
}
}
}
}
}
return b
}
;
function rstr2binl(b) {
var a = Array(b.length >> 2);
for ( var c = 0; c

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。