469,268 Members | 942 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,268 developers. It's quick & easy.

password and confirm password validation

hi all,

i wanted to check whether the password entered matches with the confirm password.either through javascript or through php.i have enclosed my code somebody help on this

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <?include 'menu.php'?>
  4. <head>
  5. <script type="text/javascript">
  6. function checkform()
  7. {
  8.   var cfname,cstatus,cuname,cpwd,cconfirmpwd;
  9.   with(window.document.createuserform)
  10.   {
  11.  
  12.     cfname=fname;
  13.     cstatus=status;
  14.     cuname=uname;
  15.     cpwd=pwd;
  16.     cconfirmpwd=confirmpwd;
  17.  
  18.   }
  19.  
  20.  
  21.      if(trim(cfname.value)=="")
  22.     {
  23.         alert("please enter the first name");
  24.         cfname.focus();
  25.         return false;
  26.     }
  27.  
  28.     else if(trim(cstatus.value)=="")
  29.     {
  30.         alert("please enter the status");
  31.         cstatus.focus();
  32.         return false;
  33.     }
  34.  
  35.     else if(trim(cuname.value)=="")
  36.     {
  37.         alert("please enter the user name");
  38.         cuname.focus();
  39.         return false;
  40.     }
  41.  
  42.     else if(trim(cpwd.value)=="")
  43.     {
  44.         alert("please enter the password");
  45.         cpwd.focus();
  46.         return false;
  47.     }
  48.  
  49.     else if(trim(cconfirmpwd.value)=="")
  50.     {
  51.         alert("confirm the password");
  52.         cconfirmpwd.focus();
  53.         return false;
  54.     }
  55.  
  56.  
  57.     else
  58.     {
  59.  
  60.          cfname.value=trim(cfname.value);
  61.          cstatus.value=trim(cstatus.value);
  62.          cuname.value=trim(cuname.value);
  63.          cpwd.value=trim(cpwd.value);
  64.          cconfirmpwd.value=trim(cconfirmpwd.value);
  65.  
  66.  
  67.     }
  68.  
  69.  
  70.     function trim(str)
  71.     {
  72.  
  73.         return str.replace(/^\s+|\s+$/g,'');
  74.  
  75.     }
  76.  
  77.  
  78.  
  79. }
  80.  
  81.  
  82.  
  83. </script>
  84.  
  85.  

Expand|Select|Wrap|Line Numbers
  1. </head>
  2. <center><h3>CREATE USER</h3></center>
  3.  
  4. <body>
  5.  
  6. <form name="createuserform" action="insertuser.php" method="POST" onsubmit="return checkform()">
  7.  
  8. <table>
  9. <td>
  10. <table border="0" cellpadding="0" cellspacing="0">
  11.  
  12.   <tr>
  13.     <td>
  14.         <table  border="0" cellpadding="0" cellspacing="0">
  15.             <tr>
  16.                 <td style="padding-left:20px;padding-bottom:20px;"><a href="createuser.php" style="text-decoration:none"><input type="button" name="new" value="CREATE USER"  style="width:170px;background-image:url(pink.gif)"></a></td>
  17.             </tr>
  18.  
  19.             <tr>
  20.                 <td style="padding-left:20px;padding-bottom:20px;"><a href="users.php" style="text-decoration:none"><input type="button" name="new" value="USERS"  style="width:170px;background-image:url(pink.gif)"></a></td>
  21.             </tr>
  22.  
  23.             <tr>
  24.                 <td style="padding-left:20px;"><a href="reassignrecords.php" style="text-decoration:none"> <input type="button" name="new" value="REASSIGN RECORDS"  style="width:170px;background-image:url(pink.gif)"></a></td>
  25.             </tr>
  26.  
  27.  
  28.         </table>
  29.     </td>
  30.     <td>
  31. <TABLE cellpadding="5" cellspacing="6" align="center" with frame="box">
  32.  
  33. <tr>
  34.  
  35.  
  36.  
  37. <th>First Name<font color="red">*</font></th>
  38. <td><input type="text" name="fname">
  39. <th>Last Name</th>
  40. <td><input type="text" name="lname">
  41. <th>Status</th>
  42. <td><select name="status">
  43. <option>Active</option>
  44. <option>Inactive</option>
  45. </select>
  46. </td>
  47.  
  48. </tr>
  49.  
  50. <tr>
  51.  
  52. <th>User Name<font color="red">*</font></th>
  53. <td><input type="text" name="uname">
  54. <th>Password<font color="red">*</font></th>
  55. <td><input type="password" name="pwd" >
  56. <th>Confirm Password<font color="red">*</font></th>
  57. <td><input type="password" name="confirmpwd">
  58.  
  59.  
  60. </tr>
  61.  
  62. <tr>
  63.  
  64. <th>Title</th>
  65. <td><input type="text" name="title">
  66. <th>Department</th>
  67. <td><input type="password" name="dept" >
  68. <th>Phone</th>
  69. <td><input type="password" name="phone">
  70.  
  71.  
  72. </tr>
  73.  
  74. <tr>
  75.  
  76. <th>Address</th>
  77. <td><input type="text" name="address">
  78. <th>City</th>
  79. <td><input type="password" name="city" >
  80. <th>Pincode</th>
  81. <td><input type="password" name="pin">
  82.  
  83.  
  84. </tr>
  85. </table>
  86. </td>
  87. </table>
  88. <br/>
  89. <br/>
  90.  
  91.  
  92. <center>
  93.  
  94.  <input type="submit" value="SAVE" style= "width:110px; height:31px; background-image: url(pink.gif)">
  95.  
  96.   <input type="button" value="CANCEL" style= "width:110px; height:31px; background-image: url(pink.gif)"></a>
  97.  
  98.  
  99. </center>
  100. </form>
  101. </body>
  102.  
  103. </html>
  104.  
  105.  
  106.  
Apr 15 '09 #1
5 40800
code green
1,726 Expert 1GB
It is normal practice to store user log-in details in a database.
Where at least the password is encrypted.
But this is not much use with Javascript.

Are you asking how to do this in php?
You will need some understanding of php to attempt this.
Apr 15 '09 #2
hi code green

yes tell me with php itself.
if it is easy to do it from client side(validation) tell me in javascript.i have enclosed my database coding that is the insertion of fields of the user(insertuser.php).the previous code was the form where the user registers himself(createuser.php).kindly check out and resolve in this very simple manner as i m a beginner for php.and the username should not be repeated.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. include 'menu.php';
  4. include 'connect.php';
  5. ?>
  6. <table border="0" cellpadding="0" cellspacing="0">
  7.  
  8.   <tr>
  9.     <td>
  10.         <table  border="0" cellpadding="0" cellspacing="0">
  11.             <tr>
  12.                 <td style="padding-left:20px;padding-bottom:20px;"><a href="createuser.php" style="text-decoration:none"><input type="button" name="new" value="CREATE USER"  style="width:170px;background-image:url(pink.gif)"></a></td>
  13.             </tr>
  14.  
  15.             <tr>
  16.                 <td style="padding-left:20px;padding-bottom:20px;"><a href="users.php" style="text-decoration:none"><input type="button" name="new" value="USERS"  style="width:170px;background-image:url(pink.gif)"></a></td>
  17.             </tr>
  18.  
  19.             <tr>
  20.                 <td style="padding-left:20px;"><a href="reassignrecords.php" style="text-decoration:none"> <input type="button" name="new" value="REASSIGN RECORDS"  style="width:170px;background-image:url(pink.gif)"></a></td>
  21.             </tr>
  22.  
  23.  
  24.         </table>
  25. <br/>
  26. <br/>
  27.  
  28. <?
  29.  
  30.  
  31.  
  32. /*
  33.   $sql="create table createuser
  34.   (
  35.       uid int(4) ,
  36.       fname varchar(20),
  37.       lname varchar(20),
  38.       status varchar(20),
  39.       uname varchar(20) primary key,
  40.       pwd varchar(20),
  41.       confirmpwd  varchar(20),
  42.       title varchar(20),
  43.       dept varchar(20),
  44.       phone bigint,
  45.       address varchar(20),
  46.       city varchar(20),
  47.       pin bigint
  48.  
  49.  
  50. )";
  51.  
  52. if(mysql_query($sql,$con))
  53. {
  54.     echo "table created";
  55. }
  56.  
  57. if(!sql)
  58. {
  59.     die(' table already exists'.mysql_error());
  60. }
  61. */
  62. $ins="insert into createuser(uid,fname,lname,status,uname,pwd,confirmpwd,title,dept,phone,address,city,pin)values('$_POST[uid]','$_POST[fname]','$_POST[lname]','$_POST[status]','$_POST[uname]','$_POST[pwd]','$_POST[confirmpwd]','$_POST[title]','$_POST[dept]','$_POST[phone]','$_POST[address]','$_POST[city]','$_POST[pin]')";
  63. $res=mysql_query($ins);
  64.  
  65. /*if(!$res)
  66. {
  67.     mysql_error();
  68. }
  69. */
  70.  
  71.  
  72. if((!$res)&&(mysql_errno()==1062))
  73. {
  74.  
  75.  
  76.          print' <b>.<font color="red" size="5">."Try another user name.This User Name already exists !!!".</font>.</b>';?>
  77.     <a href="createuser.php"> BACK </a>     
  78.     <?php
  79.     //  echo mysql_error();
  80.  
  81. }
  82. else
  83. {
  84.  
  85.     echo '<h1>'. 'A new user is  created successfully'.'</h1>';
  86.  
  87.  
  88. }
  89.  
  90.  
  91. ?>
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
Apr 15 '09 #3
code green
1,726 Expert 1GB
I can't write your code for you.

But the general idea is to collect all user log in details from a HTML form.
Then query the database to find a matching username and password.
If the query returns a record then the login is successful.
Otherwise report a problem to the user.

This is pretty basic SQL/PHP but cannot be done in Javascript.
Apr 15 '09 #4
Atli
5,058 Expert 4TB
If I'm understanding the OP correctly, he is looking for a way to match the password and the confirmation password, not to actually log the user in.
Am I right?

If so, all you would have to do is add a extra else if statement to your existing if statements in the JavaScript you posted, to match the "cconfirmpwd" variable to the "cpwd" variable, and return false if they don't match.
Apr 15 '09 #5
Markus
6,050 Expert 4TB
And to compare the values, it's as simple as

Expand|Select|Wrap|Line Numbers
  1. if ( $val1 === $val2 )
  2. {
  3.     // They match.
  4. }
  5. else
  6. {
  7.     // The don't.
  8. }
  9.  
Apr 15 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by rodchar | last post: by
1 post views Thread by =?ISO-8859-1?Q?Andr=E9?= Wyrwa | last post: by
reply views Thread by =?Utf-8?B?UmFq?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.