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.
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.