by Pieter Brinkman
14. January 2009 04:55
The following RegularExporessionValidator checks if the text-input is correct format for a user-name.
<asp:RegularExpressionValidator runat="server" ID="userNameRegexVD" ControlToValidate="userNameTxt" ValidationExpression="^([a-zA-Z])[a-zA-Z_-]*[\w_-]*[\S]$|^([a-zA-Z])[0-9_-]*[\S]$|^[a-zA-Z]*[\S]$" ErrorMessage="Invalid username" />
by Pieter Brinkman
13. January 2009 04:32
You can change the password of a MembershipUser object in C# with the ChangePassword method. The only problem of this method is that it needs the old password(string) as input parameter and I only have the hashed version off the password. To get the old password you can user the MembershipUser.ResetPassword() method. This method will reset the password and returns the new password as string.
MembershipUser user = Membership.GetUser(userNameTxt.Text);
user.ChangePassword(user.ResetPassword(), passwordTxt.Text);
Don't for get to check that the enablePasswordReset setting is true in the web.config.
<membership>
<providers>
<remove name="AspNetSqlMembershipProvider" />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="SiteSqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
applicationName="/"
requiresUniqueEmail="false"
minRequiredPasswordLength="3"
minRequiredNonalphanumericCharacters="0"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""/>
</providers>
</membership>
Goodluck!