Login.Password 屬性

定義

取得使用者輸入的密碼。

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

屬性值

使用者輸入的密碼。 預設為 null

屬性

範例

下列程式碼範例會將 Password 屬性傳遞至自訂驗證方法。

<%@ 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>

備註

屬性 Password 包含使用者輸入的密碼。 密碼為純文字。 如需詳細資訊,請參閱 Web 應用程式的基本安全性做法

注意

如果您以程式設計方式操作 UserNamePassword 屬性,請務必在頁面生命週期中的正確時間執行此動作。 和 的值 UserName 在階段中 Page_Load 無法使用,但在階段中 Pre_RenderPassword

Login 文字方塊所代表的控制項屬性,例如 UserNamePassword ,可在頁面生命週期的所有階段中存取。 控制項會透過 TextChanged 文字方塊所觸發的事件,挑選使用者所做的任何變更。

適用於

另請參閱