Code:
<script type="text/javascript">
// Encrypted Password script - by Twey, http://www.twey.co.uk/
// (only slightly based on the script of the same name by Rob Heslop)
// Released under the terms of the GNU General Public License,
// version 2 or later. See http://www.gnu.org/copyleft/gpl.html for more
// information.
var caseSensitive = true;
var pageToGoTo = "includes/%p.txt"; // %u will be replaced with username, %p with password.
var failureMessage = "Username/password combination entered incorrectly."
var caseWarning = "\nWarning: case sensitive.";
var users = [
["aa08769cdcb26674c6706093503ff0a3", "400a2c1559d060aec45227533f363d2d"]
// Add more here, in the format [usercode, passcode]
// but don't forget to add a comma to all but the last one!
];
function encrypt(str) {
/* Original algorithm:
var hash = 1;
for(var i=0;i<str.length;i++) hash *= str.charCodeAt(i);
return hash;
*/
/* Paj's MD5 implementation: */
// NOTE: MD5 has several collision weaknesses. However,
// these are not an issue here, as succeeding in creating
// a collision would only cause the script to report the
// correctness of the password incorrectly.
return hex_md5(str);
}
function passCheck(frm, user, pass) {
var form = document.forms[frm] || frm,
username = user ? (form && form.elements[user] ? form.elements[user].value : user) : form.elements["username"].value,
password = pass ? (form && form.elements[pass] ? form.elements[pass].value : pass) : form.elements["password"].value,
passcode = usercode = 1;
if(!caseSensitive) {
username = username.toLowerCase();
password = password.toLowerCase();
}
var pg = pageToGoTo.replace(/%p/g, password).replace(/%u/g, username);
passcode = encrypt(password);
usercode = encrypt(username);
for(var i = 0; i < users.length; i++)
if(users[i][0] == usercode && users[i][1] == passcode) {
if(!frm) return window.location.href = pg;
form.action = pg;
return true;
}
window.alert(failureMessage + (caseSensitive ? caseWarning : ""));
return false;
}
</script>
<form action="" onsubmit="return passCheck(this);">
<p>
<label style="display:block;">
Username:
<input type="text" name="username" size="15">
</label>
<label style="display:block;">
Password:
<input type="password" name="password" size="15">
</label>
<input type="submit" value="Submit">
</p>
</form>
Bookmarks