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);
tempPassword = user.ResetPassword();

Share This!

1 comment:

Roberth Ortiz said...

Excelente aporte amigo, gracias.!!!

Powered By Blogger · Designed By Seo Blogger Templates