ChangePassword.NewPassword Propriedade
Definição
Obtém a nova senha inserida pelo usuário.Gets the new password entered by the user.
public:
virtual property System::String ^ NewPassword { System::String ^ get(); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.Themeable(false)]
public virtual string NewPassword { get; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.Themeable(false)>]
member this.NewPassword : string
Public Overridable ReadOnly Property NewPassword As String
Valor da propriedade
A nova senha inserida pelo usuário.The new password entered by the user.
- Atributos
Exemplos
O exemplo de código a seguir mostra como usar uma página ASP.NET que usa um ChangePassword controle e inclui um manipulador para o ChangingPassword evento chamado ChangingPassword .The following code example shows how to use an ASP.NET page that uses a ChangePassword control, and includes a handler for the ChangingPassword event named ChangingPassword. ChangingPassword compara a senha antiga armazenada na CurrentPassword propriedade para a nova senha armazenada em NewPassword .ChangingPassword compares the old password stored in the CurrentPassword property to the new password stored in NewPassword. Se forem iguais, a alteração da senha falhará.If they are the same, changing the password fails.
O ChangePassword controle define a DisplayUserName propriedade como true para permitir que o usuário insira seu nome de usuário.The ChangePassword control sets the DisplayUserName property to true to enable the user to enter their user name. Isso significa que o usuário não precisa fazer logon para exibir a página.This means that the user does not have to log on to view the page.
O exemplo de código pressupõe que o site ASP.NET foi configurado para usar associação e autenticação de formulários do ASP.NET, e que um usuário foi criado cujo nome e senha são conhecidos por você.The code example assumes that the ASP.NET Web site has been configured to use ASP.NET membership and Forms authentication, and that a user has been created whose name and password are known to you. Para obter mais informações, consulte como implementar a autenticação de formulários simples.For more information, see How to: Implement Simple Forms Authentication.
<%@ 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>
Comentários
A NewPassword propriedade contém a nova senha inserida pelo usuário.The NewPassword property contains the new password entered by the user.
Você pode usar a NewPasswordRegularExpression propriedade para definir os requisitos para a nova senha.You can use the NewPasswordRegularExpression property to define the requirements for the new password. Essa expressão regular é usada para impor regras de senha no lado do cliente.This regular expression is used to enforce password rules on the client side. O NewPasswordRegularExpression não está relacionado à imposição de senha que pode ser configurada no nível de armazenamento de dados.The NewPasswordRegularExpression is not related to the password enforcement that can be configured at the data store level. A senha deve atender aos requisitos mínimos definidos pelo provedor de associação nas MinRequiredPasswordLength MinRequiredNonAlphanumericCharacters Propriedades, e PasswordStrengthRegularExpression .The password must meet the minimum requirements set by the membership provider in the MinRequiredPasswordLength, MinRequiredNonAlphanumericCharacters, and PasswordStrengthRegularExpression properties. Se a senha não atender a esses requisitos, o ChangePasswordError evento será gerado.If the password does not meet these requirements, the ChangePasswordError event is raised.
Importante
A transmissão de senhas por HTTP é uma possível ameaça à segurança.Transmitting passwords over HTTP is a potential security threat. As transmissões HTTP podem ser exibidas ou comprometidas por usuários mal-intencionados.HTTP transmissions can be viewed or compromised by malicious users. Para melhorar a segurança ao usar controles de logon, você deve usar o protocolo HTTPS com criptografia SSL para garantir que a senha do usuário não possa ser lida durante o postback.To improve security when using login controls, you should use HTTPS protocol with secure sockets layer (SSL) encryption to ensure that the user's password cannot be read during postback. Para obter mais informações, consulte Securing login Controls.For more information, see Securing Login Controls.
Esta propriedade não pode ser definida por temas ou temas de folha de estilo.This property cannot be set by themes or style sheet themes. Para obter mais informações, consulte ThemeableAttribute e temas e capas do ASP.net.For more information, see ThemeableAttribute and ASP.NET Themes and Skins.
Aplica-se a
Confira também
- ConfirmNewPassword
- NewPasswordRegularExpressionErrorMessage
- NewPasswordLabelText
- NewPasswordRegularExpression
- NewPasswordRequiredErrorMessage
- CurrentPassword
- Visão geral dos controles de logon do ASP.NETASP.NET Login Controls Overview
- Personalizando a aparência e o comportamento dos controles de logon ASP.NETCustomizing Appearance and Behavior of the ASP.NET Login Controls
- Modelos de controles de servidor Web ASP.NETASP.NET Web Server Controls Templates
- Como: exibir informações diferentes para usuários anônimos e conectadosHow to: Display Different Information to Anonymous and Logged In Users
- Guia Segurança da ferramenta de administração de siteWeb Site Administration Tool Security Tab
- Protegendo controles de logonSecuring Login Controls
- Práticas básicas de segurança para aplicativos WebBasic Security Practices for Web Applications
- Protegendo a associaçãoSecuring Membership