MembershipProvider.GetPassword(String, String) 方法

定义

从数据源获取指定用户名所对应的密码。Gets the password for the specified user name from the data source.

public:
 abstract System::String ^ GetPassword(System::String ^ username, System::String ^ answer);
public abstract string GetPassword (string username, string answer);
abstract member GetPassword : string * string -> string
Public MustOverride Function GetPassword (username As String, answer As String) As String

参数

username
String

为其检索密码的用户。The user to retrieve the password for.

answer
String

用户的密码提示问题答案。The password answer for the user.

返回

指定用户名所对应的密码。The password for the specified user name.

示例

有关MembershipProvider实现的示例,请参阅实现配置文件提供程序For an example of a MembershipProvider implementation, see Implementing a Profile Provider.

注解

采用用户名和密码答案作为输入,并从数据源中检索该用户的密码,并以字符串形式返回密码。Takes, as input, a user name and a password answer and retrieves the password for that user from the data source and returns the password as a string.

方法可确保EnablePasswordRetrieval在执行任何操作之前将标志设置为。 true GetPasswordThe GetPassword method ensures that the EnablePasswordRetrieval flag is set to true before performing any action. 如果EnablePasswordRetrievalfalseNotSupportedException则引发异常。If EnablePasswordRetrieval is false, a NotSupportedException exception is thrown.

GetPassword还检查RequiresQuestionAndAnswer属性的值。GetPassword also checks the value of the RequiresQuestionAndAnswer property. 如果RequiresQuestionAndAnswertrueGetPassword则根据数据源中存储的密码提示检查提供的应答参数的值。If RequiresQuestionAndAnswer is true, GetPassword checks the value of the supplied answer parameter against the stored password answer in the data source. 如果二者不匹配, MembershipPasswordException则会引发异常。If they do not match, a MembershipPasswordException exception is thrown.

如果自定义成员资格提供程序支持哈希GetPassword密码,则EnablePasswordRetrieval如果属性设置为true ,并且密码格式设置为Hashed,则此方法应引发异常。If your custom membership provider supports hashed passwords, the GetPassword method should throw an exception if the EnablePasswordRetrieval property is set to true and the password format is set to Hashed. 无法检索哈希密码。Hashed passwords cannot be retrieved.

适用于

另请参阅