Saturday, September 15, 2012

Change value of RequiresQuestionAndAnswer in ASP.NET Membership provider

MembershipUser user = Membership.GetUser();
string newPassword = "newPass";
string tempPassword = string.Empty;
if (Membership.Provider.RequiresQuestionAndAnswer)
{
var _requiresQA = Membership.Provider.GetType().GetField("_RequiresQuestionAndAnswer",
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
//change the value in the private field
_requiresQA.SetValue(Membership.Provider, false);
//do the reset
tempPassword = user.ResetPassword();
//set it's original value
_requiresQA.SetValue(Membership.Provider, true);
}
else
{
tempPassword = user.ResetPassword();
}

http://djsolid.net/blog/asp.net-membership---change-password-without-asking-the-old-with-question-and-answer

Share This!


1 comment:

Unknown said...

Excelente aporte amigo, gracias.!!!

Powered By Blogger · Designed By Seo Blogger Templates