473,414 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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 41811
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

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

Similar topics

0
by: Bright | last post by:
Dear All I'm after a multi-User password database so that I can centrally store system passwords and give granular access to individuals based on their own unique authentication (possibly a...
5
by: rodchar | last post by:
hey all, in my page load i'm attaching a javascript confirm message to my save button. my problem is i have some client side validation which uses a Custom Validator web control and when i make...
7
by: Nerrad | last post by:
Hi, i am currently working on a project which requires me to create a form to allow the user to change their password. I know there is a user-level security login which is easier and safer but...
1
by: znadeem | last post by:
Hi, I am new to JavaScript and I am trying to control New Password fields. These fields are not allowed to except any symbols, especially @ / \. The current code I've is not working at all. Could...
10
by: Head In A Pan | last post by:
Hello again... so soon too. I had great success (nor a novice) yesterday getting my flash form & PHP to populate my database... Now I've been asked to generate a password & then send a...
1
by: =?ISO-8859-1?Q?Andr=E9?= Wyrwa | last post by:
Hei, I know this kind of stuff has probably been asked a couple of times already, and did quite a bit of googling about it, but the answers i found were either unsatisfying or not specific...
0
by: =?Utf-8?B?UmFq?= | last post by:
In Create User Wizard, if password and confirm passowrd does not match....we get an error msg, once you set the confirm password right and without moving cursor out of the confirm password box...
0
ammoos
by: ammoos | last post by:
Hi Friends I have to install the SQL Server 2005 Express in my machine using the install shield. So I need a command line option to set the password as ‘password’. I tried to specify the password...
4
by: raj200809 | last post by:
Hi, I m trying update password in database using asp.net with c#. I have three text box in my aspx page Old password New password confirm password i m using following code but its not...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.