UserNamePasswordValidator.Validate Method (String, String)

 

When overridden in a derived class, validates the specified username and password.

Namespace:   System.IdentityModel.Selectors
Assembly:  System.IdentityModel (in System.IdentityModel.dll)

public abstract void Validate(
	string userName,
	string password
)

Parameters

userName
Type: System.String

The username to validate.

password
Type: System.String

The password to validate.

Override the Validate method to specify how the username and password is validated. If the username and password do not pass validation, then throw a SecurityTokenValidationException.

// This method validates users. It allows two users, test1 and test2 
// with passwords 1tset and 2tset respectively.
// This code is for illustration purposes only and 
// MUST NOT be used in a production environment because it is NOT secure.	
public override void Validate(string userName, string password)
{
    if (null == userName || null == password)
    {
        throw new ArgumentNullException();
    }

    if (!(userName == "test1" && password == "1tset") && !(userName == "test2" && password == "2tset"))
    {
        throw new SecurityTokenException("Unknown Username or Password");
    }
}

.NET Framework
Available since 3.0
Return to top
Show: