Udostępnij przez


ChangePassword.CurrentPassword Właściwość

Definicja

Pobiera bieżące hasło użytkownika.

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

Wartość właściwości

Bieżące hasło wprowadzone przez użytkownika.

Atrybuty

Przykłady

Poniższy przykład kodu pokazuje, jak używać strony ASP.NET korzystającej z kontrolki i zawiera procedurę ChangePassword obsługi zdarzenia ChangingPassword o nazwie ChangingPassword. Kod w procedurze ChangingPassword obsługi porównuje stare hasło przechowywane we CurrentPassword właściwości z nowym hasłem przechowywanym w NewPasswordprogramie . Jeśli te dwa hasła są takie same, zmiana hasła zakończy się niepowodzeniem.

Kontrolka ChangePassword ustawia DisplayUserName właściwość w celu true umożliwienia użytkownikom wprowadzania nazwy użytkownika. Oznacza to, że użytkownik nie musi zalogować się, aby wyświetlić stronę.

W przykładzie kodu przyjęto założenie, że witryna sieci Web ASP.NET została skonfigurowana do używania ASP.NET członkostwa i uwierzytelniania formularzy oraz że użytkownik został utworzony, którego nazwa i hasło są dla Ciebie znane. Aby uzyskać więcej informacji, zobacz Instrukcje: implementowanie uwierzytelniania prostych formularzy.

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {
    //Manually register the event-handling methods.
    ChangePassword1.ChangingPassword += new LoginCancelEventHandler(this._ChangingPassword);
  }

  void _ChangingPassword(Object sender, LoginCancelEventArgs e)
  {
    if (ChangePassword1.CurrentPassword.ToString() == ChangePassword1.NewPassword.ToString())
    {
      Message1.Visible = true;
      Message1.Text = "Old password and new password must be different.  Please try again.";
      e.Cancel = true;
    }
    else
    {
      //This line prevents the error showing up after a first failed attempt.
      Message1.Visible = false;
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>ChangePassword including a ChangingPassword event handler</title>
</head>
<body>
  <form id="form1" runat="server">
  <div style="text-align:center">

    <h1>ChangePassword</h1>
    
    <asp:LoginView ID="LoginView1" Runat="server" 
      Visible="true">
      <LoggedInTemplate>
        <asp:LoginName ID="LoginName1" Runat="server" FormatString="You are logged in as {0}." />
        <br />
      </LoggedInTemplate>
      <AnonymousTemplate>
        You are not logged in
      </AnonymousTemplate>
    </asp:LoginView><br />
    
    <asp:ChangePassword ID="ChangePassword1" Runat="server"
      BorderStyle="Solid" 
      BorderWidth="1" 
      CancelDestinationPageUrl="~/Default.aspx" 
      DisplayUserName="true" 
      OnChangingPassword="_ChangingPassword"
      ContinueDestinationPageUrl="~/Default.aspx" >
    </asp:ChangePassword><br />
  
    <asp:Label ID="Message1" Runat="server" ForeColor="Red" /><br />

    <asp:HyperLink ID="HyperLink1" Runat="server" 
      NavigateUrl="~/Default.aspx">
      Home
    </asp:HyperLink>
    
  </div>
  </form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  Public Sub PageLoad(ByVal Sender As Object, ByVal e As EventArgs)
    'Manually register the event-handling methods.
    AddHandler ChangePassword1.ChangingPassword, AddressOf Me._ChangingPassword
  End Sub

  Public Sub _ChangingPassword(ByVal Sender As Object, ByVal e As LoginCancelEventArgs)
    If (ChangePassword1.CurrentPassword.ToString() = ChangePassword1.NewPassword.ToString) Then
      Message1.Visible = True
      Message1.Text = "Old password and new password must be different.  Please try again."
      e.Cancel = True
    Else
      'This line prevents the error showing up after a first failed attempt.
      Message1.Visible = False
    End If
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>ChangePassword including a ChangingPassword event handler</title>
</head>
<body>
  <form id="form1" runat="server">
  <div style="text-align:center">

    <h1>ChangePassword</h1>
    
    <asp:LoginView ID="LoginView1" Runat="server" 
      Visible="true">
      <LoggedInTemplate>
        <asp:LoginName ID="LoginName1" Runat="server" FormatString="You are logged in as {0}." />
        <br />
      </LoggedInTemplate>
      <AnonymousTemplate>
        You are not logged in
      </AnonymousTemplate>
    </asp:LoginView><br />
    
    <asp:ChangePassword ID="ChangePassword1" Runat="server"
      BorderStyle="Solid" 
      BorderWidth="1" 
      CancelDestinationPageUrl="~/Default.aspx" 
      DisplayUserName="true" 
      OnChangingPassword="_ChangingPassword"
      ContinueDestinationPageUrl="~/Default.aspx" >
    </asp:ChangePassword><br />
  
    <asp:Label ID="Message1" Runat="server" ForeColor="Red" /><br />

    <asp:HyperLink ID="HyperLink1" Runat="server" 
      NavigateUrl="~/Default.aspx">
      Home
    </asp:HyperLink>
    
  </div>
  </form>
</body>
</html>

Uwagi

Właściwość CurrentPassword zawiera bieżące hasło wprowadzone przez użytkownika.

Ważne

Przesyłanie haseł za pośrednictwem protokołu HTTP jest potencjalnym zagrożeniem bezpieczeństwa. Transmisje HTTP można wyświetlać lub naruszać przez złośliwych użytkowników. Aby zwiększyć bezpieczeństwo podczas korzystania z kontrolek logowania, należy użyć protokołu HTTPS z szyfrowaniem secure sockets layer (SSL), aby upewnić się, że hasło użytkownika nie może być odczytywane podczas wycofywania. Aby uzyskać więcej informacji, zobacz Zabezpieczanie kontrolek logowania.

Nie można ustawić tej właściwości według motywów ani motywów arkusza stylów. Aby uzyskać więcej informacji, zobacz ThemeableAttributei ASP.NET Motywy i skóry.

Dotyczy

Zobacz też