本文整理汇总了C#中UserRepository.UpdateLastActivityDate方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.UpdateLastActivityDate方法的具体用法?C# UserRepository.UpdateLastActivityDate怎么用?C# UserRepository.UpdateLastActivityDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.UpdateLastActivityDate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPasswordWithFormat
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
private void GetPasswordWithFormat(string username,
bool updateLastLoginActivityDate,
out int status,
out string password,
out int passwordFormat,
out string passwordSalt,
out int failedPasswordAttemptCount,
out int failedPasswordAnswerAttemptCount,
out bool isApproved,
out DateTime lastLoginDate,
out DateTime lastActivityDate)
{
var dbo = new UserRepository(this.Name, _sqlConnectionString, _commandTimeout);
var user = dbo.GetUser(username);
status = -1;
password = null;
passwordFormat = 0;
passwordSalt = null;
failedPasswordAttemptCount = 0;
failedPasswordAnswerAttemptCount = 0;
isApproved = false;
lastLoginDate = DateTime.UtcNow;
lastActivityDate = DateTime.UtcNow;
if (user == null)
{
return;
}
if (user.IsLockedOut)
{
status = 99;
return;
}
status = 0;
password = user.Password;
passwordFormat = (int)user.PasswordFormat;
passwordSalt = user.Salt;
failedPasswordAttemptCount = user.FailedPasswordAttemptCount.GetValueOrDefault();
failedPasswordAnswerAttemptCount = user.FailedPasswordAnswerAttemptCount.GetValueOrDefault();
isApproved = user.IsApproved;
lastLoginDate = user.LastLoginDate.GetValueOrDefault();
lastActivityDate = user.LastActivityDate;
if (updateLastLoginActivityDate)
{
dbo.UpdateLastActivityDate(username);
lastLoginDate = DateTime.UtcNow;
lastActivityDate = DateTime.UtcNow;
}
}
示例2: GetUser
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
public override MembershipUser GetUser(string username, bool userIsOnline)
{
SecUtility.CheckParameter(
ref username,
true,
false,
true,
256,
"username");
var dbo = new UserRepository(this.Name, _sqlConnectionString, _commandTimeout);
var user = dbo.GetUser(username);
if (user == null)
return null;
if (userIsOnline)
dbo.UpdateLastActivityDate(username);
return new MembershipUser(this.Name,
user.UserName,
user.UserId,
user.Email,
user.PasswordQuestion,
null,
user.IsApproved,
user.IsLockedOut,
user.LastActivityDate,
user.LastLoginDate.GetValueOrDefault(),
user.LastLoginDate.GetValueOrDefault(),
user.LastPasswordChangedDate.GetValueOrDefault(),
user.LastLockoutDate.GetValueOrDefault());
}
示例3: 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;
}