private Discuz.Config.GeneralConfigInfo config = Discuz.Config.GeneralConfigs.GetConfig();
/// <summary>
/// 用户登录
/// </summary>
/// <param name="UserName">用户名</param>
/// <param name="Password">登陆密码</param>
/// <param name="ExpiresTime">Cookie有效时间,单位分钟</param>
/// <returns>是否登陆成功</returns>
[WebMethod]
public bool Login(string UserName, string Password, int ExpiresTime)
{
try
{
int uid = Users.CheckPassword(UserName, Password, true);
if (uid != -1)
{
ShortUserInfo userinfo = Users.GetShortUserInfo(uid);
if (userinfo != null)
{
//删除之前的错误登录信息
LoginLogs.DeleteLoginLog(DNTRequest.GetIP());
//根据积分公式刷新用户总积分
UserCredits.UpdateUserCredits(uid);
//写入用户登录后的cookie
ForumUtils.WriteUserCookie(uid, Utils.StrToInt(ExpiresTime, -1), config.Passwordkey);
//更新该用户最后访问时间
Users.UpdateUserLastvisit(uid, DNTRequest.GetIP());
}
return true;
}
else
{
LogWrite log = new LogWrite();
log.WriteLog(string.Format("用户 {0} 登陆失败:用户不存在或用户名与密码不匹配 用户IP:{1}", UserName, DNTRequest.GetIP()), DNTRequest.GetIP());
return false;
}
}
catch (Exception ex)
{
LogWrite log = new LogWrite();
log.WriteLog(ex, DNTRequest.GetIP());
return false;
}
}
/// <summary>
/// 用户登录
/// </summary>
/// <param name="UserName">用户名</param>
/// <param name="Password">登陆密码</param>
/// <param name="ExpiresTime">Cookie有效时间,单位分钟</param>
/// <returns>是否登陆成功</returns>
[WebMethod]
public bool Login(string UserName, string Password, int ExpiresTime)
{
try
{
int uid = Users.CheckPassword(UserName, Password, true);
if (uid != -1)
{
ShortUserInfo userinfo = Users.GetShortUserInfo(uid);
if (userinfo != null)
{
//删除之前的错误登录信息
LoginLogs.DeleteLoginLog(DNTRequest.GetIP());
//根据积分公式刷新用户总积分
UserCredits.UpdateUserCredits(uid);
//写入用户登录后的cookie
ForumUtils.WriteUserCookie(uid, Utils.StrToInt(ExpiresTime, -1), config.Passwordkey);
//更新该用户最后访问时间
Users.UpdateUserLastvisit(uid, DNTRequest.GetIP());
}
return true;
}
else
{
LogWrite log = new LogWrite();
log.WriteLog(string.Format("用户 {0} 登陆失败:用户不存在或用户名与密码不匹配 用户IP:{1}", UserName, DNTRequest.GetIP()), DNTRequest.GetIP());
return false;
}
}
catch (Exception ex)
{
LogWrite log = new LogWrite();
log.WriteLog(ex, DNTRequest.GetIP());
return false;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货