SqlMembershipProvider.GetPassword Method

Returns the password for the specified user name from the SQL Server membership database.

Namespace: System.Web.Security
Assembly: System.Web (in system.web.dll)

No code example is currently available or this language may not be supported.
public String GetPassword (
	String username, 
	String passwordAnswer
)
public override function GetPassword (
	username : String, 
	passwordAnswer : String
) : String
Not applicable.

Parameters

username

The user to retrieve the password for.

passwordAnswer

The password answer for the user.

Return Value

The password for the specified user name.

Exception typeCondition

System.Web.Security.MembershipPasswordException

passwordAnswer is invalid.

- or -

The membership user identified by username is locked out.

System.NotSupportedException

EnablePasswordRetrieval is set to false.

System.Configuration.Provider.ProviderException

username is not found in the membership database.

- or -

An error occurred while retrieving the password from the database.

System.ArgumentException

One of the parameter values exceeds the maximum allowed length.

- or -

username is an empty string (""), contains a comma, or is longer than 256 characters.

- or -

passwordAnswer is an empty string and RequiresQuestionAndAnswer is true.

- or -

passwordAnswer is greater than 128 characters.

- or -

The encoded version of passwordAnswer is greater than 128 characters.

System.ArgumentNullException

username is a null reference (Nothing in Visual Basic).

- or -

passwordAnswer is a null reference (Nothing in Visual Basic) and RequiresQuestionAndAnswer is true.

This method is called by the MembershipUser class to retrieve the password for a user from the SQL Server database specified in the ASP.NET application's configuration file (Web.config).

If an incorrect password answer is supplied to the GetPassword method, the internal counter that tracks invalid password-answer attempts is incremented by one. This can result in the user being locked out and unable to log on until the lock status is cleared by a call to the UnlockUser method. If the correct password answer is supplied and the user is not currently locked out, then the internal counter that tracks invalid password-answer attempts is reset to zero. For more information, see the MaxInvalidPasswordAttempts and PasswordAttemptWindow properties.

You can call the GetPassword method directly by first obtaining a reference to the SqlMembershipProvider instance through the Provider property of the Membership class.

If the PasswordFormat property is set to Hashed, the GetPassword method cannot retrieve the password. Hashed passwords are encrypted one-way and cannot be decrypted. If the PasswordFormat property is set to Hashed, and EnablePasswordRetrieval is set to true, a ProviderException is thrown when the provider is initialized.

Leading and trailing spaces are trimmed from all parameter values.

The following code example retrieves the password for a specified user name and sends it to the user in an e-mail message.

NoteNote:

Returning a password in clear text using e-mail is not recommended for sites that require a high level of security. For high-security sites, we recommend that you return passwords using encryption, such as SSL.

NoteNote:

This sample calls the SqlMembershipProvider specified as the defaultProvider in the Web.config file by using the Membership class. If you need to access the default provider as the type SqlMembershipProvider, you can cast the Provider property of the Membership class. To access other configured providers as a specific provider type, you can access them by their configured name with the Providers property of the Membership class and cast them as the specific provider type.

No code example is currently available or this language may not be supported.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: