Phiên bản đầy đủ: jsB@nk » Bảo mật » Mật khẩu » Tạo mật mã cho người dùng
URL: https://www.javascriptbank.com/multiple-users-login-table.html
Trình tạo tên đăng nhập và mật khẩu cho người sử dụng-dùng để di chuyển đến trang cá nhân được qui định.
Phiên bản đầy đủ: jsB@nk » Bảo mật » Mật khẩu » Tạo mật mã cho người dùng
URL: https://www.javascriptbank.com/multiple-users-login-table.html
<script type="text/javascript"> var userAmt; do { userAmt = prompt("How many users do you want to create?","1") } while(isNaN(userAmt)) userAmt = parseInt(userAmt,10) var formTop = "<form name='users'>" var formEnd = "</form>" var toPrint = new String(formTop) for(var i=1;i<=userAmt;i++) { toPrint += "<div style='float:left'>" toPrint += "UserName "+ i +": <input type='text' name='user"+ i +"'><BR>" toPrint += "Password "+ i +": <input type='text' name='pass"+ i +"'><BR>" toPrint += "Location "+ i +": <input type='text' name='loc"+ i +"'></div>" if(i % 3 == 0) { toPrint += (i != userAmt) ? "<BR><BR><BR><BR><BR><BR>" :"" } else { toPrint += "<div style='float:left'> </div>" } } toPrint += formEnd + (i%3>0) ? ("<BR><BR><BR><BR><BR>") : ("") toPrint += "<input type='button' value='Set Up!' onclick='setUp()'><BR><BR>Final Code [ <a href='#' onclick='execSel()'>Select All</a> | <a href='#' onclick='makeCopy()'>Copy All</a> ] :<BR><textarea id='final' rows='10' cols='30'>(no code)</textarea>" document.write(toPrint) function execSel() { document.getElementById("final").focus(); document.getElementById("final").select() } function makeCopy() { execSel() if (!document.all) { alert("Press Ctrl/Command + C to Copy the Script.") return; } var txt = document.getElementById('final') txt=txt.createTextRange(); txt.execCommand('copy'); } function setUp() { var theFrm = document.forms['users'] var user = new Array() var pass = new Array() var loc = new Array() var mid1 = "var user = new Array\n" var mid2 = " var pass = new Array\n" var mid3 = " var loc = new Array\n" for(var i=0;i<userAmt;i++) { user[i] = makeUP(theFrm['user'+ (i+1)].value) pass[i] = makeUP(theFrm['pass'+ (i+1)].value) loc[i] = makeLoc(theFrm['loc'+ (i+1)].value) mid1 += "user["+ i +"] = "+ user[i] +"\n" mid2 += "pass["+ i +"] = "+ pass[i] +"\n" mid3 += "loc["+ i +"] = "+ loc[i] +"\n" } var before = "<script type=\"text/javascript\">\n\n function checkVals(userNm,passWd) {\nvar username = \"member\"\nvar password = \"enter\"\nvar webPage = \"mySuccessPage.htm\"\n\n// declare numbers to catch errors while transferring to success webPage variable\n" var mid = mid1 +"\n"+ mid2 +"\n"+ mid3 +"\n" var after = "var chars = new Array\nvar chars2 = new Array\nfor(var i=0;i<userNm.length;i++) {\nchars[i] = userNm.charCodeAt(i).toString()\n}\n\nvar temp = new String\n\nfor(var i=0;i<chars.length;i++) {\ntemp = new String(chars[i])\nchars[i] = new Array\nfor(var j=0;j<temp.length;j++) {\nvar toUse = temp.charCodeAt(j) + Math.pow((i-j),2) - 45\ntoUse = (toUse > 255) ? (temp.charCodeAt(j) * 2 + j) : toUse\ntoUse = (toUse > 255) ? (temp.charCodeAt(j) * 3 + 8) : toUse\nchars[i][j] = toUse\n}\n} \n\nfor(var i=0;i<passWd.length;i++) {\nchars2[i] = passWd.charCodeAt(i).toString()\n}\n\nvar temp2 = new String\n\nfor(var i=0;i<chars2.length;i++) {\ntemp2 = new String(chars2[i])\nchars2[i] = new Array\nfor(var j=0;j<temp2.length;j++) {\nvar toUse2 = temp2.charCodeAt(j) + Math.pow((i-j),2) - 45\ntoUse2 = (toUse2 > 255) ? (temp2.charCodeAt(j) * 2 + j) : toUse2\ntoUse2 = (toUse2 > 255) ? (temp2.charCodeAt(j) * 3 + 8) : toUse2\nchars2[i][j] = toUse2\n}\n} \n \nfor(var i=0;i<user.length;i++) {\nif(chars.join(',') == user[i].join(',') && chars2.join(',') == pass[i].join(',')) {\nalert(\"Welcome \"+ userNm +\" !\")\nvar send = new Array(128,64,32,16,8,4,2,1)\nwindow.location = loc[i].join(',').decrypt(send.join(','))\nbreak\n}\n}\nif(i == user.length ) {\nalert(\"Incorrect User/Pass Combo.\")\ndocument.getElementById('user').focus()\ndocument.getElementById('user').select()\n}\n }\n\n String.prototype.decrypt = function(send) {\nvar values = this.split(',')\nvar returnVal = \"\"\nvar vals = send.split(',')\nvar conDit\nfor(var i=0;i<vals.length;i++) {\nconDit += \"vals[i] == vals[i]-1\"\nif(i < vals.length - 1) {\nconDit += \" && \"\n}\nelse if(i > vals.length) {\ntry {\nif(i == 1) throw 1;\nelse if(i == 2) throw 2;\nelse if(i == 3) throw 3;\nelse if(i == 4) throw 4;\nelse throw Math.floor(Math.random()*96)+5;\n}\ncatch(err) {\nif(err == 1) returnVal += \"PassWord Incorrect.\";\nelse if(err == 2) returnVal += \"PassWord Correct. (enter)\";\nelse if(err == 3) returnVal += \"UserName Incorrect.\";\nelse if(err == 4) returnVal += \"UserName Correct. (member)\";\nelse returnVal += getErr(i);\n}\n}\n}\nfor(var k=0;k<vals[vals.length-1];k++) {\nfor(var i=0;i<values.length;i++) {\nif(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(!(conDit))))))))))))))))))))))))) {\nreturnVal += String.fromCharCode(values[i]-10)\n}\n}\n}\nreturn (returnVal.length == 0) ? \"mySuccessPage.htm // webPage\" : returnVal\n }\n\n function getErr(val) {\nvar i = Math.round(Math.pow(Math.pow(Math.PI,.5),val))\nif(rind(gone(rind(gone(i)))) == 0) return 0\nelse if(rind(gone(i)) <= 10) return 1\nelse return 2\n }\n\n function rind(val) {\nvar num = new Number(0)\nfor(var i=0;i<String.fromCharCode(val);i++) {\nnum += i\n}\nreturn num\n }\n\n function gone(val) {\nvar char = val.charCodeAt(0)\nvar str = new String(\"\")\nvar num = new Number(0)\nfor(var i=0;i<val;i++) {\nstr += i +\", \"\nstr += char\n}\nfor(var i=0;i<str.length;i++) {\nnum += i\n}\nreturn num\n }\n\n</s"+"cript>\n<form onsubmit=\"document.getElementById('sub').click();return false;\">\nUser Name: <input type=\"text\" id=\"user\"><BR>\nPassword: <input type=\"password\" id=\"pass\"><BR>\n<input type=\"submit\" id=\"sub\" value=\"Check User\" onclick=\"checkVals(document.getElementById('user').value,document.getElementById('pass').value)\">\n</form>" document.getElementById('final').value = before + mid + after } function makeUP(stringForCon) { var chars = new Array for(var i=0;i<stringForCon.length;i++) { chars[i] = stringForCon.charCodeAt(i).toString() } var temp = new String for(var i=0;i<chars.length;i++) { temp = new String(chars[i]) chars[i] = new Array for(var j=0;j<temp.length;j++) { var toUse = temp.charCodeAt(j) + Math.pow((i-j),2) - 45 toUse = (toUse > 255) ? (temp.charCodeAt(j) * 2 + j) : toUse toUse = (toUse > 255) ? (temp.charCodeAt(j) * 3 + 8) : toUse chars[i][j] = toUse } } return ("new Array("+ chars.join(',') +")") } function makeLoc(strText) { var theResult = "new Array(" for(var i=0;i<strText.length;i++) { theResult += (strText.charCodeAt(i) + 10) if(i < strText.length - 1) { theResult += "," } } return (theResult +")") } </script><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->