0

In my Custom member ship provider I have provided implementation for the ValidateUser and things were fine so far but now suddenly PasswordFormat have started throwing

NotImplementedException was unhandled by user code

There is no change in my web.config or Custom Membership. Some of the stack overflow answers referring to add the role manager under system.web in Web.config but it didn't work for me. Also, I have tried the answer suggested by Josh here but still no difference. I am using Hexa decimal encoding.

None of the other apart from ValidateUser is implemented in my custom membership, which is as follow

    public override bool ValidateUser(string username, string password)
    {
        LoginModel model = new LoginModel
        {
            UserName = username,
            Password = password,
            ErrorMessage = ""
        };

        User user = UserManager.AuthenticateUser(model);

        if (user != null)
        {
            HttpContext.Current.Items.Add("User", user);
            return true;
        }

        return false;
    }
Learning Curve
  • 1,449
  • 7
  • 30
  • 60

1 Answers1

0

Sharing my solution here in case if someone else needs it.

PasswordFormat value can be defined in web config and then provide implementation by reading its value in the PasswordFormat of MembershipPasswordFormat as explained here.

    public override MembershipPasswordFormat PasswordFormat
    {
        string temp_format = config["passwordFormat"];  
        if (temp_format == null)  
        {  
            temp_format = "Hashed";  
        }  

        switch (temp_format)  
        {  
            case "Hashed":  
                passwordFormat = MembershipPasswordFormat.Hashed;  
                break;  
            case "Encrypted":  
                passwordFormat = MembershipPasswordFormat.Encrypted;  
                break;  
            case "Clear":  
                passwordFormat = MembershipPasswordFormat.Clear;  
                break;  
            default:  
                throw new ProviderException("Password format not supported.");  
        }
    } 

If someone don't want to set the value in web.config, it can also be set in the Membership Password Format as membership stuff hardly every changes during the life time of an application.

Learning Curve
  • 1,449
  • 7
  • 30
  • 60