Check password length on Asp.Net C#

Posted on 2006-06-08
Last Modified: 2008-01-09
I write application using (C#). Allow user register. I want write a control validate password length on field password. Minimum = 6. Please help me!
Question by:thanhh83
    LVL 6

    Expert Comment

    check that the field length is greater than 6
    LVL 6

    Accepted Solution

    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

    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.
    LVL 1

    Expert Comment

    please be aware that sensitive validation should be done server side too, because a malicious user could bypass any client side script.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    This article will show, step by step, how to integrate R code into a R Sweave document
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now