PDA

View Full Version : Variation on Encryted Password script



voobass
07-02-2006, 07:57 PM
Hello,

I am using DD's Encrypted password script and it works fine UNTIL I change the form submit from a button:

<input type="button" value="Submit" onClick="submitentry()"></form>

to an image:

<input type="image" src="i/enter.gif" onClick="submitentry()"></form>

How can I use an image button with this script: http://www.dynamicdrive.com/dynamicindex9/password.htm (http://http://www.dynamicdrive.com/dynamicindex9/password.htm)

Twey
07-02-2006, 09:15 PM
I don't think much of this script.
<script type="text/javascript">
// Encrypted Password script - by Twey
// (only slightly based on the script of the same name by Rob Heslop)
// Script featured on Dynamic Drive
// Visit http://www.dynamicdrive.com/

// User-editable vars.

var caseSensitive = false;
var pageToGoTo = "%p.html"; // %u for username, %p for password.
var failureMessage = "Username/password combination entered incorrectly."
var caseWarning = "\nWarning: case sensitive.";
var users = [
[168698684, 143676400]
// Add more here, in the format [usercode, passcode]
// but don't forget to add a comma to all but the last one!
];

// End of user-editable vars.

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);
for(var i = 0; i < password.length || i < username.length; i++) {
if(i < password.length) passcode *= password.charCodeAt(i);
if(i < username.length) usercode *= username.charCodeAt(i);
}
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);">
<input type="text" name="username" size="15">
<label>
Password:
<input type="password" name="password" size="15">
</label>
<input type="submit" value="Submit">
</form>
The case sensitivity requires that you use a new calculation function if you want a case-sensitive username and password:
function calculate(user, pass, caseSens) {
var username = caseSens ? user : user.toLowerCase(),
password = caseSens ? pass : pass.toLowerCase(),
usercode = passcode = 1;
for(i = 0; i < password.length || i < username.length; i++) {
if(i < password.length) passcode *= password.charCodeAt(i);
if(i < username.length) usercode *= username.charCodeAt(i);
}
return [usercode, passcode];
}If you don't know what to do with that, ignore it and leave caseSensitive as false. :)

This script should handle image inputs just as easily as standard submit buttons. It also allows submission of the form in other ways, such as by pressing enter.

voobass
07-02-2006, 09:31 PM
Thanks! A couple questions:


I don't think much of this script....

I relpaced the 168698684, 143676400 with the values generated for my login and when I press submit I get a blank white page. Is there more to the configuration? As well, will your script allow me to substitute <input type="image" src="i/enter.gif"> for <input type="submit" value="Submit">? I really need to use an image in place of the Submit button.

voobass
07-02-2006, 09:36 PM
[QUOTE=Twey] TweyQUOTE]

Sorry...I figured out how you wanted it configured. It works great with the image button, too. Thanks again!

shriniwas
12-26-2007, 03:19 PM
The Script is gr8 !!
It helped me alot thanks for it....

:)