Usted está anulando el método incorrecto, Steve. Desea anular el ChangingPassword
cancelable.
Prueba esto:
protected void ChangePassword1_ChangingPassword(object sender, LoginCancelEventArgs e)
{
// do your lookup here,
bool passwordHasBeenPreviouslyUsed = true;
if (passwordHasBeenPreviouslyUsed)
{
e.Cancel = true;
// notify of error
return;
}
}
Y, según sesiones anteriores Q/A, nunca se debe NUNCA NUNCA almacén de contraseñas de un usuario . Diríjase a la tabla de membresía y obtenga la sal y utilícela para ajustar la contraseña entrante para compararla con los valores ya almacenados en su tabla de búsqueda.
Buena suerte.
(1) - ¿Cuán posible sería su posición cuando el CEO descubra que su contraseña ha sido almacenada en un formato explotable? Hay un nivel de confianza dado a los magos negros que somos nosotros y esa confianza conlleva sus propios riesgos. Sé consciente de ellos. ;-)
EDITAR:
Un ejemplo de trabajo:
ChangePassword.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Diagnostics"%>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ChangePassword1_ChangingPassword(object sender, LoginCancelEventArgs e)
{
// works for me!
Debugger.Break();
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ChangePassword ID="ChangePassword1" runat="server" OnChangingPassword="ChangePassword1_ChangingPassword">
</asp:ChangePassword>
</div>
</form>
</body>
</html>
actualización: Usted también podría estar interesado en definir simplemente un controlador en una Alcance más alto que observará toda la actividad de contraseñas:
considere esto
public void SetupPasswordActionHook()
{
//Occurs when a user is created, a password is changed, or a password is reset.
Membership.ValidatingPassword += Membership_ValidatingPassword;
}
void Membership_ValidatingPassword(object sender, ValidatePasswordEventArgs e)
{
// Gets a value that indicates whether the System.Web.Security.MembershipProvider.ValidatingPassword event is being raised during a
// call to the System.Web.Security.MembershipProvider.CreateUser() method.
// true if the System.Web.Security.MembershipProvider.ValidatingPassword event is being raised during a call to the
// System.Web.Security.MembershipProvider.CreateUser() method; otherwise, false.
bool isNewUser = e.IsNewUser;
// Gets the password for the current create-user, change-password, or reset-password action.
// The password for the current create-user, change-password, or reset-password action.
string password = e.Password;
// Gets the name of the membership user for the current create-user, change-password, or reset-password action.
// The name of the membership user for the current create-user, change-password, or reset-password action.
string username = e.UserName;
// Gets or sets a value that indicates whether the current create-user, change-password, or reset-password action will be canceled.
// true if the current create-user, change-password, or reset-password action will be canceled; otherwise, false. The default is false.
e.Cancel = true;
// Gets or sets an exception that describes the reason for the password-validation failure.
// An System.Exception that describes the reason for the password-validation failure.
e.FailureInformation = new Exception("This is why I failed your password");
}
No estoy seguro de lo que está tratando de hacer aquí. Usted habla sobre querer verificar contraseñas antiguas, pero su declaración SQL recupera los nombres de usuario y nunca revisa las contraseñas. ¿Cómo está verificando la contraseña? – cortijon
Sí, estás en lo cierto, esa parte del código está en una página diferente, fui muy rápido armando una página de prueba, disculpa la confusión. Simplemente tuve problemas para interrumpir el proceso en sí. Gracias por su aporte. – Steve
¿Algún progreso en este caso? –