Click here to Skip to main content
12,354,533 members (59,413 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: .NET
How to strenghten the password for a registration page and how to validate it in asp.net c#


I want some characters,numbers,Special characters,




<td style="text-align: left; width: 90px;">
                                   Password
                               </td>
                               <td style="font-family: Verdana; font-size: medium; font-style: normal; text-align: left">
                                   <asp:TextBox ID="txtpassword" runat="server" Width="208px" ></asp:TextBox>
                                   <asp:RegularExpressionValidator ID="regpass" runat="server"
                                       ErrorMessage="RegularExpressionValidator" ControlToValidate="txtpassword"
                                       ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                               </td>
Posted 2-Sep-12 19:37pm
Shibiny580
Edited 2-Sep-12 21:17pm
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Validating password with
-must be 8 characters including 1 uppercase letter, 1 special character & alphanumeric characters
(?=.*\d)        #   must contain at least one digit
(?=.*[A-Z])     #   must contain at least one uppercase character
(?=.*\W)        #   must contain at least one special symbol
   .            #   match anything with previous condition checking
{8,8}           #   length at least 8 characters and also maximum of 8
In one line:
((?=.*\d)(?=.*[A-Z])(?=.*\W).{8,8})
Sources:
* Password matching expression[^]
* Password Strength Validation with Regular Expressions[^]
* ASP.Net Regular Expression Validator to validate Minimum and Maximum Text Length[^]
  Permalink  
Comments
Mohamed Mitwalli 3-Sep-12 2:21am
   
5+
Prasad_Kulkarni 3-Sep-12 2:32am
   
Thank you Mohamed!
Shibiny 3-Sep-12 2:31am
   
I Used your code like this:

<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="RegularExpressionValidator" ControlToValidate="txtpassword"
ValidationExpression="((?=.*\d)(?=.*[A-Z])(?=.*\W).{8,8})">
It Worked fine,But data after error message,Entered data saved to database,how to prevent this
Prasad_Kulkarni 3-Sep-12 2:33am
   
Use retrun, if error occurs.
Shibiny 3-Sep-12 3:00am
   
How to do this
Shibiny 3-Sep-12 3:01am
   
add new event is not working after showing this error message
lukeer 3-Sep-12 3:12am
   
Show the relevant code snippet. Use the "Improve question" link for that (directly beneath your original question).
Shibiny 3-Sep-12 3:30am
   
How to use it in javascript
Manas Bhardwaj 3-Sep-12 6:07am
   
yup +5
Prasad_Kulkarni 3-Sep-12 6:13am
   
Thank you Manas!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100