Membership修改用户密码

Membership本身不提供管理员修改用户密码的方法,只能通过用户的邮箱及问题找回,此方法在实际应用中不实现,解决方法如下:
1。 requiresQuestionAndAnswer="false"   requiresQuestionAndAnswer一定要设成FALSE,不然是无法强型更改用户密码的;
程序代码 程序代码
<membership defaultProvider="sqlprovider" userIsOnlineTimeWindow="15">
            <providers>
                <add name="SqlProvider"
                      type="System.Web.Security.SqlMembershipProvider"
                      connectionStringName="aspnetdbConnectionString"
                     requiresQuestionAndAnswer="false"
                        minRequiredPasswordLength="4"
                     maxInvalidPasswordAttempts="5"    
                     applicationName="CBC"
                     requiresUniqueEmail="false"
                        minRequiredNonalphanumericCharacters="0"/>
            </providers>
        </membership>


2。C#里的方法如下:

程序代码 程序代码
try
        {
            string name = Request.QueryString["username"];//获取更改的用户名
            string password = TextBox1.Text;//新密码
            MembershipUser users = Membership.GetUser(name);
            string oldps = users.ResetPassword();//系统自动重设密码
            users.ChangePassword(oldps, password);//密码变更
            //Response.Write("OK");
            WebMessageBox.Show("ok", true);
        }
        catch (Exception ex)
        {
            WebMessageBox.Show(ex.Message);
        }
posted @ 2008-05-28 10:16  bany  阅读(549)  评论(0编辑  收藏  举报