2011-03-10 107 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和其他散列函數是不可逆的單向函數,它們不是加密的),但它們可以完全繞過它,並使其看起來像他們知道正確的密碼。 –