Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript html登录安全问题_Javascript_Html - Fatal编程技术网

Javascript html登录安全问题

Javascript html登录安全问题,javascript,html,Javascript,Html,有人知道如何在数据库访问中隐藏此登录密码吗?此html页面未发布。这可能是在web应用程序中实现身份验证的最不安全的方法。所有这些信息都将以明文形式通过网络发送 您还总是将用户信息的大小写为小写,因此凭据变得更加不安全 构建认证系统的典型方法是: 创建一个接受用户名和密码的表单 通过对照数据库表中的信息对服务器端的用户信息进行评估来验证用户信息 根据凭据的成功或失败向客户端返回响应 所有这些都取决于正确和安全地注册用户。为此: 接受注册表中的用户名和密码 对指定的密码应用哈希和salt 将

有人知道如何在数据库访问中隐藏此登录密码吗?此html页面未发布。

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

您还总是将用户信息的大小写为小写,因此凭据变得更加不安全

构建认证系统的典型方法是:

  • 创建一个接受用户名和密码的表单
  • 通过对照数据库表中的信息对服务器端的用户信息进行评估来验证用户信息
  • 根据凭据的成功或失败向客户端返回响应
所有这些都取决于正确和安全地注册用户。为此:

  • 接受注册表中的用户名和密码
  • 对指定的密码应用哈希和salt
  • 将信息序列化到数据库
在以后的所有登录尝试中,您都希望通过相同的散列和salt将用户传入的信息与存储在数据库表中的记录进行比较

问题是,根据您使用的平台的不同,实现类似的功能会有很大的不同


在客户端进行评估时,最接近客户端验证的方法是使用Ajax防止页面刷新。

如果无法在客户端验证密码,则需要在服务器上检查密码。然后,生成的页面必须确保已检查密码。换句话说,你不能依靠“除了我的脚本,没有人知道URL”来保护页面


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

您的问题相当笼统。没有简单、简短的答案。首先,您的服务器中需要一个数据库。然后您必须使用服务器中的某种脚本(使用PHP、ruby或类似的工具)来访问它。最后一步是将用户和密码输入发送到服务器,在那里进行检查,然后返回响应

尝试在网上寻找PHP教程,并阅读它。这会让你的想法更清晰一些。

(如果只是为了满足我内心的学究的话)。如果说没有服务器端工具包就不能进行任何类型的密码安全,这是不准确的。使用JS SHA-1实现并在源代码中存储(salt)密码散列是完全可行的

诚然,这不是理想的解决方案,因为共享PWD并不那么酷

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!");
    }
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */
/*SHA-1在JavaScript中的实现|(c)Chris Vesies 2002-2010 | www.movable-type.co.uk*/
/*-见http://csrc.nist.gov/groups/ST/toolkit/secure_hashing.html                             */
/*         http://csrc.nist.gov/groups/ST/toolkit/examples.html                                   */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */
var Sha1={};//Sha1命名空间
/**
*生成字符串的SHA-1哈希
*
*@param{String}msg要哈希的字符串
*@param{Boolean}[utf8encode=true]在生成哈希之前将消息编码为UTF-8
*@返回消息的{String}哈希值作为十六进制字符串
*/
Sha1.hash=函数(msg,utf8encode){
utf8encode=(utf8encode的类型=‘未定义’)?true:utf8encode;
//将字符串转换为UTF-8,因为SHA只处理字节流
如果(utf8encode)msg=Utf8.encode(msg);
//常数[§4.2.1]
变量K=[0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6];
//预处理
msg+=String.fromCharCode(0x80);//将尾部的“1”位(+0的填充)添加到字符串[§5.1.1]
//将字符串msg转换为512位/16整数块整数数组[§5.2.1]
var l=msg.length/4+2;//msg+'1'+附加长度的长度(以32位整数表示)
var N=Math.ceil(l/16);//保存“l”整数所需的16个整数块的数目
var M=新数组(N);

对于(var i=0;请下次正确格式化您的代码。谢谢!)你不能对用户隐藏javascript中所做的任何事情。你需要在服务器上管理身份验证。@trufa我不知道如何格式化文本我希望你没有为此获得报酬。这会让我哭泣。@peter im do这不是销售,只是为了我现在所学的主题的练习基础。+1但这比doi要复杂得多这是客户端!啊,是的。我应该更改我的答案吗?:)现在这个页面还没有发布,我只是想知道是否有任何方法可以在MS access上访问登录密码。是的。你应该告诉他用一些简单的字符替换算法将用户名和密码与字符串混淆。@CKK999你无法获取服务器端信息没有在服务器端实际运行请求的情况下在客户机上进行登录。现在此页面尚未发布,我只想知道是否有任何方法可以在MS access上访问登录密码。您的问题与MS access无关。您需要使用从该密码派生的密钥对文档进行加密。而普通SHA-1不适用于此呃,因为它太快了。应该使用PKDF2之类的密钥派生函数。“你需要用从该密码派生的密钥对文档进行加密。”-嗯?密码不需要解密,更不用说文档了。“普通SHA-1也不适合,因为它太快。”-比光速快?/麋鹿?“应该使用PKDF2之类的密钥派生函数”-现在我知道我有麻烦了..在web浏览器中执行的任何操作都可能被用户破解。他们可能无法发现密码(因为根据定义,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>