PDA

View Full Version : How do I enable the return key to work like the submit button for password field?


ahab55
02-13-2003, 08:45 PM
I am using the encrypted password generator located at javascriptkit.com. Unfortunatley, when you enter the password and hit the enter key, it will not submit the info. You have to click on the submit button for it to work. Hitting the enter key only clears the field. I would appreciate it if anyone could show me how I should modify the following script to enable this.

Thanks in advance!

<script>

var pass=new Array()
var t3=""
var lim=7
pass[0]="zAjpbfPjN1T2Jnb"
pass[1]="xJkLHWo4ryVmLZ"
pass[2]="UgP7PhDKzMvCL5t"
pass[3]="IxEgJyCxHLGRCi"
pass[4]="8Zz7DXNzfQFNOnvj"
pass[5]="48Zz7DXNzfQFNOnv"

//configure extension to reflect the extension type of the target web page (ie: .htm or .html)
var extension=".html"
var enablelocking=0
var numletter="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
var temp3=''
var cur=0


function max(which){
return (pass[Math.ceil(which)+(3&15)].substring(0,1))
}

function testit(input){
temp=numletter.indexOf(input)
var temp2=temp^parseInt(pass[phase1-1+(1|3)].substring(0,2))
temp2=numletter.substring(temp2,temp2+1)
return (temp2)
}


function submitentry(){
t3=''
verification=document.password1.password2.value
phase1=Math.ceil(Math.random())-6+(2<<2)
var indicate=true
for (i=(1&2);i<window.max(Math.LOG10E);i++)
t3+=testit(verification.charAt(i))
for (i=(1&2);i<lim;i++){
if (t3.charAt(i)!=pass[phase1+Math.round(Math.sin(Math.PI/2)-1)].charAt(i))
indicate=false
}
if (verification.length!=window.max(Math.LOG10E))
indicate=false
if (indicate)
window.location=verification+extension
else
alert("Invalid password. Please try again")
}
</script>



<table border="1" cellspacing="0" cellpadding="0" bgcolor="#FFFFBD">
<tr>
<td width="100%"><form name="password1"><div align="center"><center><p><strong>Enter password: </strong><input
type="text" name="password2" size="15"><br>
<input type="button" value="Submit" onClick="submitentry()"></p>
</center></div>
</form>
</td>
</tr>
</table>

Philip M
02-13-2003, 09:35 PM
You should try the following adjustments:-

else
alert("Invalid password. Please try again");
document.form.password2.focus();
}
</script>



align="center"><center><p><strong>Enter password: </strong><input
type="text" name="password2" size="15" onBlur="submitentry()"></p>


It is confusing to name the form "password1" and the textbox "password2". Why not call the form "passform" or something?

whammy
02-15-2003, 01:02 PM
P.S. Encrypted or not, this can be broken with brute force (although it would probably take quite awhile) easier than simply trying to guess passwords, since the encryption scheme is readily available.

I'd do something simpler, like Borgtex's script here:

http://www.codingforums.com/showthread.php?s=&threadid=10114

I also updated it to be XHTML 1.1 compliant here:

http://www.solidscripts.com/displayscript.asp?sid=15

redhead
02-15-2003, 01:37 PM
although this isnt what your asking... im sure there was a javascript password protection script that none of us could get through... cant remember what the url was though *goes to search on the old forum archive*

found it... http://htmlhq.tripod.com/generator/index.htm... although if you disabled javascript it would be oh so easy...

l3vi
02-16-2003, 03:01 AM
I dont know if it works with the return key but:
<button accesskey="yourkey">Submit</button>

or like a lot of programs do:
<button accesskey="S"><u>S</u>ubmit</button> which is where if the user presses alt+S it will automaticly submit.

whammy
02-16-2003, 03:08 AM
If you read and understand this tutorial part, you will see what you need to do to modify the script!

Instead of using <input type="button"> it would be better as a submit button which submits the form ONLY if the function returns a "true" boolean value:

http://hotwired.lycos.com/webmonkey/98/04/index3a_page5.html?tw=programming

cheesebagpipe
02-16-2003, 03:12 AM
<form name="password1" onsubmit="submitentry();return false;">
<div align="center"><center><p><strong>Enter password: </strong><input
type="text" name="password2" size="15"><br>
<input type="button" value="Submit"></p>
</center></div>
</form>

Nice touch:

if (indicate)
window.location=verification+extension;
else {
alert("Invalid password. Please try again");
document.password1.password2.focus();
document.password1.password2.select();
}
}