Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ASP.Net MembershipProvider : Auto generate password without nonalfanumaric character

0.00/5 (No votes)
6 Jan 2008 1  
Using ASP.Net MembershipProvider Auto Generate Password with does not contain nonalfanumaric character

Introduction

In an application that uses Asp.Net MembershipProvider, in the membership process if you don't want to use character except letter in your generated password that send to your given e-mail address, you have to follow below steps.
Unfortunately it seems complicated and in my opinion there is a design mistake related MembershipProvider.

Using the code

It requires some changes with CreateUserWizard control :
For this create new web control derived by CreateUserWizard control and override Password property.

    ToolboxData("<{0}:MyCreateUserWizard runat="server"></{0}:MyCreateUserWizard>")]
    public class MyCreateUserWizard : CreateUserWizard
    {
        
        public MyCreateUserWizard()
            : base()
        {
        
        }

        private string generatedPassword = string.Empty;

        public override string Password
        {
            get
            {
                if (string.IsNullOrEmpty(generatedPassword))
                    generatedPassword = GeneratePassword();

                return generatedPassword;
            }
        }
        

    }
        

And if you want same feature with PasswordRecovery control, you have to create new class derived by System.Web.Security.SqlMembershipProvider and override GeneratePassword method.

 public class MyMembershipProvider : System.Web.Security.SqlMembershipProvider
    {       

        public MyMembershipProvider()
            : base()
        {
        }
                
        public override string GeneratePassword()
        {
            ....
        }
    }    

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here