Login.Password Właściwość

Definicja

Pobiera hasło wprowadzone przez użytkownika.

public:
 virtual property System::String ^ Password { System::String ^ get(); };
[System.ComponentModel.Browsable(false)]
public virtual string Password { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Password : string
Public Overridable ReadOnly Property Password As String

Wartość właściwości

Hasło wprowadzone przez użytkownika. Wartość domyślna to null.

Atrybuty

Przykłady

Poniższy przykład kodu przekazuje Password właściwość do niestandardowej metody uwierzytelniania.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
private bool SiteSpecificAuthenticationMethod(string UserName, string Password)
{
    // Insert code that implements a site-specific custom 
    // authentication method here.
    //
    // This example implementation always returns false.
    return false;
}

private void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
    bool Authenticated = false;
    Authenticated = SiteSpecificAuthenticationMethod(Login1.UserName, Login1.Password);

    e.Authenticated = Authenticated;
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">
            <asp:Login id="Login1" runat="server"
                OnAuthenticate="OnAuthenticate">
            </asp:Login>
        </form>
    </body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Function SiteSpecificAuthenticationMethod(ByVal UserName As String, ByVal Password As String) As Boolean
    ' Insert code that implements a site-specific custom 
    ' authentication method here.
    '
    ' This example implementation always returns false.
    Return False
End Function

Sub OnAuthenticate(ByVal sender As Object, ByVal e As AuthenticateEventArgs)
    Dim Authenticated As Boolean
    Authenticated = SiteSpecificAuthenticationMethod(Login1.UserName, Login1.Password)

    e.Authenticated = Authenticated
End Sub


</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">
            <asp:Login id="Login1" runat="server"
                OnAuthenticate="OnAuthenticate">
            </asp:Login>

        </form>
    </body>
</html>

Uwagi

Właściwość Password zawiera hasło wprowadzone przez użytkownika. Hasło jest w postaci zwykłego tekstu. Aby uzyskać więcej informacji, zobacz Podstawowe praktyki zabezpieczeń dla aplikacji internetowych.

Uwaga

Jeśli programowo manipulujesz UserName właściwościami lub Password , ważne jest, aby to zrobić w odpowiednim czasie podczas cyklu życia strony. Wartości i UserNamePassword nie są dostępne w Page_Load fazie, ale są w Pre_Render fazie.

Login właściwości kontrolki reprezentowane przez pola tekstowe, takie jak UserName i Password, są dostępne we wszystkich fazach cyklu życia strony. Kontrolka będzie pobierać wszelkie zmiany wprowadzone przez użytkownika końcowego TextChanged za pomocą zdarzenia wyzwalanego przez pola tekstowe.

Dotyczy

Zobacz też