Stai ignorando il metodo sbagliato, Steve. Si desidera ignorare il cancellabile ChangingPassword
.
provare questo:
protected void ChangePassword1_ChangingPassword(object sender, LoginCancelEventArgs e)
{
// do your lookup here,
bool passwordHasBeenPreviouslyUsed = true;
if (passwordHasBeenPreviouslyUsed)
{
e.Cancel = true;
// notify of error
return;
}
}
E, come da precedenti sessioni di Q/A, non si dovrebbe mai MAI MAI memorizzazione delle password di un utente . Vai alla tabella dei membri e prendi il sale e usalo per cancellare la password in entrata per confrontarla con i valori già saltati che hai salvato nella tua tabella di ricerca.
Buona fortuna.
(1) - quanto è probabile la tua posizione quando il CEO scopre che la sua password è stata archiviata in un formato sfruttabile? C'è un livello di fiducia dato ai maghi neri che siamo noi e che la fiducia comporta i suoi rischi. Sii consapevole di loro. ;-)
EDIT:
Un esempio di lavoro:
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>
Aggiornamento: Potreste anche essere interessati a definire semplicemente un gestore in un ambito più alto che guarderà tutte le attività della password:
considera questo
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");
}
Non sono sicuro di cosa stai provando a fare qui. Si parla di voler verificare le vecchie password, ma l'istruzione SQL recupera nomi utente e non verifica mai le password. Come stai verificando la password stessa? – cortijon
Sì, hai ragione, quel pezzo di codice si trova su una pagina diversa, sono stato davvero veloce a mettere insieme una pagina di test, mi dispiace per la confusione. Ho appena avuto problemi a interrompere il processo stesso. Grazie per l'input. – Steve
Qualche progresso su questo? –