Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Using StrComp() for Client-side password verification 1

Status
Not open for further replies.

Jables

Programmer
Aug 28, 2001
148
US
I'm pretty new to asp and I'm using the following script to validate a password submission. The form is called passwordverify and the two fields are password and passconfirm.

I have the script located before the html and head tags. When I hit the submit button on the form I get HTTP 405 error from the browser.

Anyone know what's wrong with this scenario?



<SCRIPT LANGUAGE=&quot;VBScript&quot;>

<-- Option Explicit

'Define variables to be used in the function
Dim validation

'pulls data from form fields puts them into variables
Dim varpassword
if (Request.Form(&quot;password&quot;) <> &quot;&quot;) then varpassword = Request.Form(&quot;password&quot;)

Dim varpassconfirm
if (Request.Form(&quot;passconfirm&quot;) <> &quot;&quot;) then varpassconfirm = Request.Form(&quot;passconfirm&quot;)

Function passwordverify_OnSubmit

Dim same

'do a case sensitive comparison of the strings
same = StrComp(varpassword, varpassconfirm, 0)


'if the password and passconfirm fields are different then display a message box and set validation to false otherwise set validation to True and get on with submitting the form
if same = 0 then validation = True
else
validation = False
msgbox &quot;Password mismatch in password and confirm password fields. Click OK and reenter your password. You're getting there kiddo.&quot;,8
end if


if validation = True then passwordverify_OnSubmit = True
else
passwordverify_OnSubmit = False
end if

End Function
</SCRIPT>
 
Use JavaScript for this. Here's a perfect example.


<html>
<head>
<script Language=&quot;JavaScript&quot;>
<!--
function checkForm(form_obj) {
if (form_obj.password.value != form_obj.passconfirm.value) {
window.alert(&quot;Password does not match Confirm Password.&quot;)
form_obj.password.value = &quot;&quot;
form_obj.passconfirm.value = &quot;&quot;
form_obj.password.focus()
return false
}
return true
}
// -->
</script>
</head>
<body>
<form name=&quot;myform&quot; action=&quot;nextpage.asp&quot; method=&quot;post&quot; onSubmit=&quot;return checkForm(this);&quot;>

<!--Your Form Elements Here-->

</form>
</body>
</html>


This should work just fine. Let me know if you need more help..

ToddWW :)
 
Works like a charm. Thanks a bunch. Do you have any thoughts on why it's better to use JavaScript instead of VBScript in this case? Like I said in my first post, I'm new to this stuff and I'd like to learn as much as possible.

Clay
 
Yes, as far as I know, you'll run into problems with client side VBScript in Netscape.

JavaScript works in ALL !! :)

Well, just about all.. :-(

ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top