本文整理汇总了C#中UserRepository.UnlockAccount方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.UnlockAccount方法的具体用法?C# UserRepository.UnlockAccount怎么用?C# UserRepository.UnlockAccount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.UnlockAccount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnlockUser
public override bool UnlockUser(string username)
{
SecUtility.CheckParameter(ref username, true, true, true, 256, "username");
var dbo = new UserRepository(this.Name, _sqlConnectionString, _commandTimeout);
var user = dbo.GetUser(username);
if (user == null)
return false;
return dbo.UnlockAccount(username);
}
示例2: CheckPassword
private bool CheckPassword(string username, string password, bool updateLastLoginActivityDate, bool failIfNotApproved, out string salt, out int passwordFormat)
{
string passwdFromDB;
int status;
int failedPasswordAttemptCount;
int failedPasswordAnswerAttemptCount;
bool isApproved;
DateTime lastLoginDate, lastActivityDate;
GetPasswordWithFormat(username, updateLastLoginActivityDate, out status, out passwdFromDB, out passwordFormat, out salt, out failedPasswordAttemptCount,
out failedPasswordAnswerAttemptCount, out isApproved, out lastLoginDate, out lastActivityDate);
if (status != 0)
return false;
if (!isApproved && failIfNotApproved)
return false;
string encodedPasswd = EncodePassword(password, passwordFormat, salt);
bool isPasswordCorrect = passwdFromDB.Equals(encodedPasswd);
if (isPasswordCorrect && failedPasswordAttemptCount == 0 && failedPasswordAnswerAttemptCount == 0)
return true;
var dbo = new UserRepository(this.Name, _sqlConnectionString, _commandTimeout);
var user = dbo.GetUser(username);
// set out parameters
passwordFormat = (int)user.PasswordFormat;
salt = user.Salt;
if (user.IsLockedOut)
return false;
DateTime dtNow = DateTime.UtcNow;
if (!isPasswordCorrect)
{
user.FailedPasswordAnswerAttemptWindowStart = user.FailedPasswordAnswerAttemptWindowStart ?? DateTime.UtcNow.AddYears(-2);
if (dtNow > user.FailedPasswordAnswerAttemptWindowStart.Value.AddMinutes(_passwordAttemptWindow))
{
dbo.PasswordAttemptCountClear(username);
}
dbo.FailedPasswordAttemptIncrement(username);
if (user.FailedPasswordAnswerAttemptCount.GetValueOrDefault() >= failedPasswordAnswerAttemptCount)
{
dbo.LockAccount(username);
}
}
else
{
if (user.FailedPasswordAnswerAttemptCount.GetValueOrDefault() > 0 || user.FailedPasswordAnswerAttemptCount.GetValueOrDefault() > 0)
{
dbo.UnlockAccount(username);
}
}
dbo.UpdateLastActivityDate(username);
return isPasswordCorrect;
}