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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Confirm Passwords

Status
Not open for further replies.

jedel

Programmer
Jan 11, 2003
430
AU
I have a page where member can change their passwords. I want to be able to have a confirm password field to check thatthey have entered the new password correctly.

How do I go about
a) comparing the two fields, and
b) sending a message to the user if they do not match


-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
have you tried anything so far or have some code that you can provide? This is very easy to do, but it's not going to be as easy to get the answer unless you have done some of the work yourself..

If you haven't written any code yet, here's how to start:


1. on the Client side using javascript: get the values of each field and if they match return true, otherwise alert the user and return false. This check can be done onchange or on sumbit of the form.

2. On the server side (using ASP)get each value from the form using a request.form or request.querystring (depending on how you posted your form), compare them.

In an if/else/endif block:

if a <> b then 'values do not match
response.write "passwords do not match, go back and double check them"
else
' execute code as normal.
end if


TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
I've actually tried both methods.

I'm tending toward the javascript side purely because it is all done on the one page. here is my poor attempt at javascript
Code:
<script type="text/javascript">
<!--
function MM_popupMsg(msg) { //v1.0
  alert(msg);
}
//-->

function pwdmacth(){
var txtpwd = request.Form("txtpwd");
var txtpwd2 = request.Form("txtpwd2");

if txtpwd <> txtpwd2 then
MM_popupMsg("Passwords do not match");
end if
}
</script>

I called the function from the button "onClick" event like this: onclick="javascript(pwdmacth)"

Feel free to rip it apart, it didn't work anyway

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
You might want to ask at the Javascript forum

"end if" and "then" and "<>" aren't the same as VBScript.

it'd be more like...

if (txtpwd != txtpwd2){
MM_popupMsg("Passwords do not match");
}

and

Request.Form("txtpwd");

like

document.getElementById("txtpwd").value;

so on...
 
It is hopelessly mixing vbs, javascript, server-side (request) and client-side (onclick...).
>Feel free to rip it apart, it didn't work anyway.
Just not the right attitude.
 
MarkZK,

Thanks for the input, I'll go over to the javascript forukms and see what they have.

Tsuji

Hey, Never said I was good at javascript. But I did try. If was good at it, I would not need to come to you guys for help. I have been trying to do this now for weeks and getting no real help.

Is what I am asking for really that hard to understand?

two fields, one checked against the other and a message popping up if they do not match.

I do not care how it is done. I would prefer client side as it means I don't have to build extra pages but hey...what ever works.

So, attitude? lets get past how people feel and maybe help solve a problem? I can sort my attitude out by talking to someone.



-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
[1] If you ask javascript forum, the response would be the same: client-side validation is not enough for anything of importance, in particular, for password. You can have client-side validation as a preliminary measure. The final say must be on the server-side validation.

[2] This is the float.
[ol]
[li]x.htm or x.asp (asking for personal data)[/li]
[li]y.asp (page x.htm submitted to)[/li]
[li]z.htm or z.asp (page redirected if validated, else back to x.htm)[/li]
[/ol]
[2.1] x.htm
[tt]
<html>
<body>
<form name="formname" method="post" action="y.asp"
onsubmit="if (this.pwd_prm.value.length==0 || this.pwd_prm.value != this.pwd_cfm.value) {return false;}">
<label style="font:monospace;" for="username">
name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</label>
<input name="username" id="username" type="text" /><br />
<label style="font:monospace;" for="pwd_prm">
password&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</label>
<input name="pwd_prm" id="pwd_prm" type="password" /><br />
<label style="font:monospace;" for="pwd_cfm">
re-type to confirm
</label>
<input name="pwd_cfm" id="pwd_cfm" type="password" /><br />
<input type="submit" /><br />
</form>
</body>
</html>
[/tt]
[2.2] y.asp
[tt]
<%
spwd_prm=request.form("pwd_prm")
spwd_cfm=request.form("pwd_cfm")
if strcomp(spwd_prm,spwd_cfm,0)=0 then
response.redirect("z.htm")
else
response.redirect("x.htm")
end if
%>
[/tt]
[2.3] z.htm
[tt]
<html>
<body>
<div>your personal data and password are accepted.</div>
</body>
</html>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top