UserNamePasswordValidator.Validate(String, String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当在派生类中重写时,验证指定的用户名和密码。
public:
abstract void Validate(System::String ^ userName, System::String ^ password);
public abstract void Validate (string userName, string password);
abstract member Validate : string * string -> unit
Public MustOverride Sub Validate (userName As String, password As String)
参数
- userName
- String
要验证的用户名。
- password
- String
要验证的密码。
示例
// 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");
}
}
' 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 方法以指定如何验证用户名和密码。 如果用户名和密码没有通过验证,则引发 SecurityTokenValidationException。