[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4168
  • Last Modified:

Check password length on Asp.Net C#

I write application using asp.net (C#). Allow user register. I want write a control validate password length on field password. Minimum = 6. Please help me!
Thanks
0
thanhh83
Asked:
thanhh83
1 Solution
 
willbdmanCommented:
check that the field length is greater than 6
0
 
TDSnetCommented:
If you want do the validation client-side, without posting back to the server (which I assume you would), you can use one of the built in ASP.NET validation controls.  The best way would be to use a RegularExpressionValidator in the following way:

<asp:TextBox ID=txtPassword Runat=server TextMode=Password />
<asp:RegularExpressionValidator Runat=server ControlToValidate=txtPassword ValidationExpression="^[A-Za-z0-9]{6,10}$">
    Minimum 6 Characters
</asp:RegularExpressionValidator>

The regular expression I have used here will check that the password contains only alphanumeric characters and that it is between 6 and 10 characters in length.
0
 
MySt1kCommented:
please be aware that sensitive validation should be done server side too, because a malicious user could bypass any client side script.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now