.NET Framework Class Library
UserNamePasswordValidator Class

Validates a username and password.

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

Visual Basic (Declaration)
Public MustInherit Class UserNamePasswordValidator
Visual Basic (Usage)
Dim instance As UserNamePasswordValidator
C#
public abstract class UserNamePasswordValidator
Visual C++
public ref class UserNamePasswordValidator abstract
JScript
public abstract class UserNamePasswordValidator
Remarks

Use the UserNamePasswordValidator class to specify how a username and password is validated. This can be done by deriving a class from UserNamePasswordValidator and override the Validate method. For more information about creating a custom user name and password validator, see How to: Use a Custom User Name and Password Validator.

Examples

Visual Basic
Public Class MyCustomUserNameValidator
    Inherits UserNamePasswordValidator

    ' 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 Overrides Sub Validate(ByVal userName As String, ByVal password As String)
        If Nothing = userName OrElse Nothing = password Then
            Throw New ArgumentNullException()
        End If

        If Not (userName = "test1" AndAlso password = "1tset") AndAlso Not (userName = "test2" AndAlso password = "2tset") Then
            Throw New SecurityTokenException("Unknown Username or Password")
        End If

    End Sub 'Validate
End Class 'MyCustomUserNameValidator
C#
public class MyCustomUserNameValidator : UserNamePasswordValidator
{
    // 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");
        }
    }
}
Inheritance Hierarchy

System..::.Object
  System.IdentityModel.Selectors..::.UserNamePasswordValidator
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Tags :


Community Content

philodendrite
using a custom validator with net.tcp binding
I've tried this with net.tcp binding, but it still seems to be using windows authentication. The custom validator is never called and

OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name


is the windows id of the caller rather than the username set with


ChannelFactory.Credentials.UserName.UserName



Is another step needed in the binding?

Tags :

Page view tracker