2011-03-10 108 views
0
function LogIn() { 
    loggedin = false; 
    username = ""; 
    password = ""; 
    username = prompt("Username:", ""); 
    username = username.toLowerCase(); 
    password = prompt("Password:", ""); 
    password = password.toLowerCase(); 
    if (username == "user" && password == "123") { 
     loggedin = true; 
     window.location = "video embed.html"; 
    } 
    if (loggedin == false) { 
     alert("Invalid login!"); 
    } 
} 

任何机构知道如何将这个登录密码隐藏到数据库访问?此html页面未发布。html登录安全问题

+0

下次请正确格式化您的代码。谢谢! :) – Trufa

+1

您无法隐藏用户在JavaScript中完成的任何操作。您需要管理服务器上的身份验证。 – David

+0

@trufa我不知道如何格式化文本 – CKK9999

回答

1

这可能是在Web应用程序中实现身份验证的最不安全的方式。所有这些信息将以纯文本的形式通过网络发送。

您也一直在降低用户的信息,因此凭证变得更加安全。

的典型方法着手建立了一个认证系统将是:

  • 创建一个接受用户名和密码
  • 通过评估其对验证的服务器端的用户信息的形式信息在数据库表中。
  • 返回基于证书

所有这一切都在正确牢固的注册用户队伍的成功或失败的客户端的响应。要做到这一点:

  • 接受登记表格
  • 用户名和密码应用哈希和盐,以指定的密码
  • 序列化信息数据库

在所有未来登录尝试时,您需要通过传递相同的散列和盐值来评估用户传入的信息与存储在数据库表中的记录。

事情是,根据您使用的平台,实现类似这样的差异很大。

就客户端评估这一点而言,最接近客户端验证的是使用Ajax来防止页面刷新。

+1

+1但是这比仅仅做客户端要复杂得多! –

+0

啊,真的。我应该改变我的答案吗? :) – Tom

+0

现在这个网页没有发布,只是我想知道有任何方法可以访问MS Access上的登录密码。 – CKK9999

0

您无法验证客户端上的密码,您需要检查服务器上的密码。然后生成的页面必须确保密码已被检查。换句话说,您不能依赖“没有人知道除我的脚本之外的URL”这一事实来保护页面。

有很多方法可以做到这一点,实际上大多数Web服务器都有内置的URL保护方式。

+0

现在这个网页没有发布,只是我想知道有什么方法可以访问MS Access上的登录密码。 – CKK9999

+1

您的问题与MS Access无关 –

1

你的问题是相当一般的。没有简单的答案。首先,你的服务器需要一个数据库。然后你必须通过服务器中的某种脚本访问它(使用PHP,ruby或类似的东西)。最后一步是将用户和密码输入发送到服务器,在那里检查它们并发送回应。

尝试在网上找一个PHP教程阅读它。它应该让你的想法更清晰一点。

0

(如果只是为了满足我内心的嘲笑)。没有服务器端套件,说你不能做任何类型的密码安全性是不准确的。使用JS SHA-1实现并在源代码中存储(腌制)密码散列是非常可行的。

无可否认,这不是一个理想的解决方案,因为共享密码并不那么酷。

<html> 
<script> 

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 
/* SHA-1 implementation in JavaScript | (c) Chris Veness 2002-2010 | www.movable-type.co.uk  */ 
/* - see http://csrc.nist.gov/groups/ST/toolkit/secure_hashing.html        */ 
/*   http://csrc.nist.gov/groups/ST/toolkit/examples.html         */ 
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 

var Sha1 = {}; // Sha1 namespace 

/** 
* Generates SHA-1 hash of string 
* 
* @param {String} msg    String to be hashed 
* @param {Boolean} [utf8encode=true] Encode msg as UTF-8 before generating hash 
* @returns {String}     Hash of msg as hex character string 
*/ 
Sha1.hash = function(msg, utf8encode) { 
    utf8encode = (typeof utf8encode == 'undefined') ? true : utf8encode; 

    // convert string to UTF-8, as SHA only deals with byte-streams 
    if (utf8encode) msg = Utf8.encode(msg); 

    // constants [§4.2.1] 
    var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6]; 

    // PREPROCESSING 

    msg += String.fromCharCode(0x80); // add trailing '1' bit (+ 0's padding) to string [§5.1.1] 

    // convert string msg into 512-bit/16-integer blocks arrays of ints [§5.2.1] 
    var l = msg.length/4 + 2; // length (in 32-bit integers) of msg + ‘1’ + appended length 
    var N = Math.ceil(l/16); // number of 16-integer-blocks required to hold 'l' ints 
    var M = new Array(N); 

    for (var i=0; i<N; i++) { 
    M[i] = new Array(16); 
    for (var j=0; j<16; j++) { // encode 4 chars per integer, big-endian encoding 
     M[i][j] = (msg.charCodeAt(i*64+j*4)<<24) | (msg.charCodeAt(i*64+j*4+1)<<16) | 
     (msg.charCodeAt(i*64+j*4+2)<<8) | (msg.charCodeAt(i*64+j*4+3)); 
    } // note running off the end of msg is ok 'cos bitwise ops on NaN return 0 
    } 
    // add length (in bits) into final pair of 32-bit integers (big-endian) [§5.1.1] 
    // note: most significant word would be (len-1)*8 >>> 32, but since JS converts 
    // bitwise-op args to 32 bits, we need to simulate this by arithmetic operators 
    M[N-1][14] = ((msg.length-1)*8)/Math.pow(2, 32); M[N-1][14] = Math.floor(M[N-1][14]) 
    M[N-1][15] = ((msg.length-1)*8) & 0xffffffff; 

    // set initial hash value [§5.3.1] 
    var H0 = 0x67452301; 
    var H1 = 0xefcdab89; 
    var H2 = 0x98badcfe; 
    var H3 = 0x10325476; 
    var H4 = 0xc3d2e1f0; 

    // HASH COMPUTATION [§6.1.2] 

    var W = new Array(80); var a, b, c, d, e; 
    for (var i=0; i<N; i++) { 

    // 1 - prepare message schedule 'W' 
    for (var t=0; t<16; t++) W[t] = M[i][t]; 
    for (var t=16; t<80; t++) W[t] = Sha1.ROTL(W[t-3]^W[t-8]^W[t-14]^W[t-16], 1); 

    // 2 - initialise five working variables a, b, c, d, e with previous hash value 
    a = H0; b = H1; c = H2; d = H3; e = H4; 

    // 3 - main loop 
    for (var t=0; t<80; t++) { 
     var s = Math.floor(t/20); // seq for blocks of 'f' functions and 'K' constants 
     var T = (Sha1.ROTL(a,5) + Sha1.f(s,b,c,d) + e + K[s] + W[t]) & 0xffffffff; 
     e = d; 
     d = c; 
     c = Sha1.ROTL(b, 30); 
     b = a; 
     a = T; 
    } 

    // 4 - compute the new intermediate hash value 
    H0 = (H0+a) & 0xffffffff; // note 'addition modulo 2^32' 
    H1 = (H1+b) & 0xffffffff; 
    H2 = (H2+c) & 0xffffffff; 
    H3 = (H3+d) & 0xffffffff; 
    H4 = (H4+e) & 0xffffffff; 
    } 

    return Sha1.toHexStr(H0) + Sha1.toHexStr(H1) + 
    Sha1.toHexStr(H2) + Sha1.toHexStr(H3) + Sha1.toHexStr(H4); 
} 

// 
// function 'f' [§4.1.1] 
// 
Sha1.f = function(s, x, y, z) { 
    switch (s) { 
    case 0: return (x & y)^(~x & z);   // Ch() 
    case 1: return x^y^z;     // Parity() 
    case 2: return (x & y)^(x & z)^(y & z); // Maj() 
    case 3: return x^y^z;     // Parity() 
    } 
} 

// 
// rotate left (circular left shift) value x by n positions [§3.2.5] 
// 
Sha1.ROTL = function(x, n) { 
    return (x<<n) | (x>>>(32-n)); 
} 

// 
// hexadecimal representation of a number 
// (note toString(16) is implementation-dependant, and 
// in IE returns signed numbers when used on full words) 
// 
Sha1.toHexStr = function(n) { 
    var s="", v; 
    for (var i=7; i>=0; i--) { v = (n>>>(i*4)) & 0xf; s += v.toString(16); } 
    return s; 
} 


/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 
/* Utf8 class: encode/decode between multi-byte Unicode characters and UTF-8 multiple   */ 
/*    single-byte character encoding (c) Chris Veness 2002-2010       */ 
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 

var Utf8 = {}; // Utf8 namespace 

/** 
* Encode multi-byte Unicode string into utf-8 multiple single-byte characters 
* (BMP/basic multilingual plane only) 
* 
* Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars 
* 
* @param {String} strUni Unicode string to be encoded as UTF-8 
* @returns {String} encoded string 
*/ 
Utf8.encode = function(strUni) { 
    // use regular expressions & String.replace callback function for better efficiency 
    // than procedural approaches 
    var strUtf = strUni.replace(
     /[\u0080-\u07ff]/g, // U+0080 - U+07FF => 2 bytes 110yyyyy, 10zzzzzz 
     function(c) { 
     var cc = c.charCodeAt(0); 
     return String.fromCharCode(0xc0 | cc>>6, 0x80 | cc&0x3f); } 
    ); 
    strUtf = strUtf.replace(
     /[\u0800-\uffff]/g, // U+0800 - U+FFFF => 3 bytes 1110xxxx, 10yyyyyy, 10zzzzzz 
     function(c) { 
     var cc = c.charCodeAt(0); 
     return String.fromCharCode(0xe0 | cc>>12, 0x80 | cc>>6&0x3F, 0x80 | cc&0x3f); } 
    ); 
    return strUtf; 
} 

/** 
* Decode utf-8 encoded string back into multi-byte Unicode characters 
* 
* @param {String} strUtf UTF-8 string to be decoded back to Unicode 
* @returns {String} decoded string 
*/ 
Utf8.decode = function(strUtf) { 
    // note: decode 3-byte chars first as decoded 2-byte strings could appear to be 3-byte char! 
    var strUni = strUtf.replace(
     /[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g, // 3-byte chars 
     function(c) { // (note parentheses for precence) 
     var cc = ((c.charCodeAt(0)&0x0f)<<12) | ((c.charCodeAt(1)&0x3f)<<6) | ( 

c.charCodeAt(2)&0x3f); 
     return String.fromCharCode(cc); } 
    ); 
    strUni = strUni.replace(
     /[\u00c0-\u00df][\u0080-\u00bf]/g,     // 2-byte chars 
     function(c) { // (note parentheses for precence) 
     var cc = (c.charCodeAt(0)&0x1f)<<6 | c.charCodeAt(1)&0x3f; 
     return String.fromCharCode(cc); } 
    ); 
    return strUni; 
} 

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 

function LogIn() { 
    loggedin = false; 
    username = ""; 
    password = ""; 
    username = prompt("Username:", ""); 
    username = username; 
    password = prompt("Password:", ""); 
    salt  = "jenny"; 
    password = Sha1.hash(salt + password); 

    if (username == "user" && password == "8c84bbf4f643d6b8c4c188935eb1196d8cdcf10b") { 
     loggedin = true; 
    alert("valid login!") 
     //window.location = "video embed.html"; 
    } 
    if (loggedin == false) { 
     alert("Invalid login!"); 
    } 
} 


</script> 

<body onload="LogIn();"> 

</body> 
</html> 
+0

您需要使用该密码派生的密钥加密文档。由于速度太快,所以普通的SHA-1对此不太好。应该使用PKDF2等密钥派生函数。 – CodesInChaos

+0

“您需要使用从该密码派生的密钥来加密文档。” - 嗯?密码不需要解密,不必介意文档。 “简单的SHA-1不适合这个,因为它太快了。” - 比光速更快? /一只麋鹿? “应该使用PKDF2等密钥派生函数” - 现在我知道我有麻烦了。 – trickwallett

+0

任何在您的Web浏览器中完成的操作,用户都可以破解。他们可能无法发现密码(因为根据定义,SHA-1和其他散列函数是不可逆的单向函数,它们不是加密的),但它们可以完全绕过它,并使其看起来像他们知道正确的密码。 –