Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

Something like this? The booleans are there so you can warn the user if you didn't send an email. That said, I agree with SilverlightFox's answer SilverlightFox's answer; allowing users to reset each other's passwords is probably a bad idea.

private bool SendNewPasswordToUserByEmail(string email)
{
 return SendNewPasswordToUser(Membership.GetUserNameByEmail(email ?? String.Empty));
}
private bool SendNewPasswordToUser(string userName)
{
 MembershipUser mu = Membership.GetUser(userName ?? String.Empty);
 if (mu == null)
 {
 return false;
 }
 string password = mu.ResetPassword();
 EmailPassword(password, mu.Email);
 return true;
}

Personally, I'd add another if to check for null rather than using ??, but you said to reduce use of conditionals.

Something like this? The booleans are there so you can warn the user if you didn't send an email. That said, I agree with SilverlightFox's answer; allowing users to reset each other's passwords is probably a bad idea.

private bool SendNewPasswordToUserByEmail(string email)
{
 return SendNewPasswordToUser(Membership.GetUserNameByEmail(email ?? String.Empty));
}
private bool SendNewPasswordToUser(string userName)
{
 MembershipUser mu = Membership.GetUser(userName ?? String.Empty);
 if (mu == null)
 {
 return false;
 }
 string password = mu.ResetPassword();
 EmailPassword(password, mu.Email);
 return true;
}

Personally, I'd add another if to check for null rather than using ??, but you said to reduce use of conditionals.

Something like this? The booleans are there so you can warn the user if you didn't send an email. That said, I agree with SilverlightFox's answer; allowing users to reset each other's passwords is probably a bad idea.

private bool SendNewPasswordToUserByEmail(string email)
{
 return SendNewPasswordToUser(Membership.GetUserNameByEmail(email ?? String.Empty));
}
private bool SendNewPasswordToUser(string userName)
{
 MembershipUser mu = Membership.GetUser(userName ?? String.Empty);
 if (mu == null)
 {
 return false;
 }
 string password = mu.ResetPassword();
 EmailPassword(password, mu.Email);
 return true;
}

Personally, I'd add another if to check for null rather than using ??, but you said to reduce use of conditionals.

Source Link
Brian
  • 548
  • 3
  • 18

Something like this? The booleans are there so you can warn the user if you didn't send an email. That said, I agree with SilverlightFox's answer; allowing users to reset each other's passwords is probably a bad idea.

private bool SendNewPasswordToUserByEmail(string email)
{
 return SendNewPasswordToUser(Membership.GetUserNameByEmail(email ?? String.Empty));
}
private bool SendNewPasswordToUser(string userName)
{
 MembershipUser mu = Membership.GetUser(userName ?? String.Empty);
 if (mu == null)
 {
 return false;
 }
 string password = mu.ResetPassword();
 EmailPassword(password, mu.Email);
 return true;
}

Personally, I'd add another if to check for null rather than using ??, but you said to reduce use of conditionals.

lang-cs

AltStyle によって変換されたページ (->オリジナル) /