UserNamePasswordValidator 类

定义

验证用户名和密码。

public ref class UserNamePasswordValidator abstract
public abstract class UserNamePasswordValidator
type UserNamePasswordValidator = class
Public MustInherit Class UserNamePasswordValidator
继承
UserNamePasswordValidator

示例

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");
        }
    }
}
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
End Class

注解

使用 UserNamePasswordValidator 类来指定验证用户名和密码的方式。 可通过从 UserNamePasswordValidator 派生类并重写 Validate 方法来完成此操作。 有关创建自定义用户名和密码验证程序的详细信息,请参阅 如何:使用自定义用户名和密码验证程序

构造函数

UserNamePasswordValidator()

初始化 UserNamePasswordValidator 类的新实例。

属性

None

获取不对用户名和密码执行验证的验证程序。 因此,用户名和密码总是被视为有效。

方法

CreateMembershipProviderValidator(MembershipProvider)

获取 UserNamePasswordValidator 的实例,它使用指定的成员资格提供程序来验证用户名和密码。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)
Validate(String, String)

当在派生类中重写时,验证指定的用户名和密码。

适用于