473,598 Members | 3,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

password and confirm password validation

27 New Member
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 41835
code green
1,726 Recognized Expert Top Contributor
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
ahilar12
27 New Member
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(createu ser.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 Recognized Expert Top Contributor
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 Recognized Expert Expert
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 "cconfirmpw d" variable to the "cpwd" variable, and return false if they don't match.
Apr 15 '09 #5
Markus
6,050 Recognized Expert Expert
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
2949
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 securID token). I've been keeping a watchful eye for such a system but to no avail ..... has anybody come across such a system? ... I'll be most grateful top hear about such a system!
5
2083
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 the validation go off and hit save, it allows me to postback with the error. Am i doing something wrong? thanks, rodchar
7
4378
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 was told that i could and even must not use it. GOD KNOWS WHY So i created a custom login form with userID and password which validates with a table containing all the users and their passwords. Then, i thought it would be easier to allow the...
1
4535
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 someone help please. function changepass_submit() { if (document.Eform.USERNAME.value=="") { alert("Please Enter Value for Username"); document.Eform.USERNAME.focus();} else if (document.Eform.PASSWORD.value=="") { alert("Please Enter Value...
10
1927
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 validation email! Perhaps simple for some - impossible for me! I've added some code which has basically stopped the data being set to my database at all. ;( Can anyone see anything wrong with my code?
1
2578
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 enough to what i want to do: I'm writing on a (Linux only) python daemon that runs as regular user. Under certain conditions the daemon should create a total screen lock as
0
1406
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 click on the "Create user" button...the page will not be posted the only difference will make it the error msg will be moved out and if you click again the "Create user" button ....then user account will be created. This happens only in IE not in...
0
885
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 as ‘password’. But error displayed by saying “Strong Password Required” Please help me thanks
4
22713
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 resolving
0
7904
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8398
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8051
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8267
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5850
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5438
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3898
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3940
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2414
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.