Alphanumeric Password C#.net

Last post 09-02-2008 8:22 PM by sudheerbabum. 7 replies.

Sort Posts:

  • Alphanumeric Password C#.net

    09-02-2008, 6:36 PM
    • Member
      22 point Member
    • sudheerbabum
    • Member since 06-12-2008, 8:41 PM
    • USA
    • Posts 25

    Hello groupies,

    I am doing a small web application, in this the user needs to get registered. During registartion , the password field should accept only alphanumeric values with minimum lenght 8, what exactly do I need to do for it  and What datatype do I need to use for it ? How can I set maximum and minimum lenght ?

    Your reply is greatly appreciated..

    Regards
    MSB

  • Re: Alphanumeric Password C#.net

    09-02-2008, 6:45 PM
    • Star
      11,568 point Star
    • Bruce L
    • Member since 02-08-2007, 6:53 PM
    • Posts 1,935

    You can consider using ASP.NET's built in validation control.  There are many posting on the internet on how to do this.

    http://www.vkinfotek.com/validationcontrols.html

    Bruce
    DiscountASP.NET - ASP.NET Hosting Experts
    Voted 2009 "Best ASP.NET Hosting" by asp.netPRO Magazine
    Win2008/IIS7.0, ASP.NET 2.0/3.5 SP1, MVC, AJAX, Silverlight, SQL 2008/2005
  • Re: Alphanumeric Password C#.net

    09-02-2008, 6:57 PM
    • Member
      22 point Member
    • sudheerbabum
    • Member since 06-12-2008, 8:41 PM
    • USA
    • Posts 25

    Hi Thanks for your reply..

    I used two validation controls..

    One is regualr expression for geting alpha numeric value  and

    the other one is range validator to give maximum and minimum lenght

    I gave maximum lenght as 15 and minimum lenght as 7..

     

    when I debug I am getting an exception

    Exception Details: System.Web.HttpException: The MaximumValue 15 cannot be less than the MinimumValue 7 of RVP.

    Is there anything wrong with usage of Range validator ???

     

    Regards

     

    MSB

  • Re: Alphanumeric Password C#.net

    09-02-2008, 7:18 PM
    • Participant
      1,240 point Participant
    • viscious
    • Member since 04-11-2006, 6:32 PM
    • Denver
    • Posts 216

    I have never used a range validator, and i don't think they can be used to validate the number of characters in a text field (i might be wrong about that though).   I would use a regex validator to determine text length, you can probably make a regex that validates the alphanumeric and the length properties with one validator.

     

    Something like this

     

    <asp:RegularExpressionValidator ID="Val1" runat="server" ValidationExpression="[a-zA-Z1-9]{7,15}" ControlToValidate="tb1" ErrorMessage="invalid" />
      

     

  • Re: Alphanumeric Password C#.net

    09-02-2008, 7:20 PM
    • Member
      22 point Member
    • sudheerbabum
    • Member since 06-12-2008, 8:41 PM
    • USA
    • Posts 25

    Hi I have used the regular expression for alphanumeric in whihc I have given lenght too..

    [a-zA-Z0-9]*\w{6,15}

     Minimum 6 characters are being accepted but it is accepting  normal passwords like "classic" whihc is not alphanumeric.. I need

    the textbox should take passwords like "Classic3"  , "14modern"

     Your reply is greatly apprecited ..

     

    Regards

    MSB

  • Re: Alphanumeric Password C#.net

    09-02-2008, 7:31 PM
    • Star
      11,568 point Star
    • Bruce L
    • Member since 02-08-2007, 6:53 PM
    • Posts 1,935

    I never use both validation as well but I think sudheerbabum's solution should work fine.

    Bruce
    DiscountASP.NET - ASP.NET Hosting Experts
    Voted 2009 "Best ASP.NET Hosting" by asp.netPRO Magazine
    Win2008/IIS7.0, ASP.NET 2.0/3.5 SP1, MVC, AJAX, Silverlight, SQL 2008/2005
  • Re: Alphanumeric Password C#.net

    09-02-2008, 7:54 PM
    • Member
      22 point Member
    • sudheerbabum
    • Member since 06-12-2008, 8:41 PM
    • USA
    • Posts 25

    Hi,

    I want.. it should have definitely a number and a letter..

    it should not accept if all the charaters are letters and all the characters are numbers..

     

    Reagrds

    MSB

  • Re: Alphanumeric Password C#.net

    09-02-2008, 8:22 PM
    Answer
    • Member
      22 point Member
    • sudheerbabum
    • Member since 06-12-2008, 8:41 PM
    • USA
    • Posts 25

    Hello,
    Thanks for your help.

    Using this regular expression we can get an alpha numeric password

    (?=^.{6,}$)(?=.*\d)(?=.*\W+)(?![.\n]).*$

    for more information visit

    http://en.csharp-online.net/ASP.NET_Security_Hacks%E2%80%94Validating_a_Strong_Password_in_Login_Controls

    Regards
    MSB

     

Page 1 of 1 (8 items)