Esempio n. 1
0
 public void Submit()
 {
     try
     {
         M.Member member = DbTable.Load <M.Member>(Request.Form);
         if (!V.MobileHash.Equals(DataSource, member.Mobile, V.MobileHash.Password, Request.Form["Captcha"]))
         {
             SetResult((int)M.LoginStatus.CaptchaError);
             return;
         }
         M.Member temp = M.Member.Get(DataSource, member.Mobile.ToString());
         if (temp == null)
         {
             SetResult((int)M.LoginStatus.NotFound);
             return;
         }
         member.Id = temp.Id;
         SetResult(member.Update(DataSource, ColumnMode.Include, "Password") == DataStatus.Success);
     }
     catch (Exception ex)
     {
         SetResult(false, ex.Message);
     }
 }
Esempio n. 2
0
 private static LoginStatus Login(DataSource ds, string type, string userId, string ip, string mark, out Member member, out Guid token)
 {
     member = null;
     token  = Guid.Empty;
     if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(userId))
     {
         ds.Begin();
         try
         {
             LoginStatus result;
             long        memberId = ExecuteScalar <OAuth2Member, long>(ds, "MemberId", P("Type", type) & P("UserId", userId));
             if (memberId > 0)
             {
                 member = Member.GetById(ds, memberId);
                 if (member != null)
                 {
                     if (member.Approved)
                     {
                         if (member.Locked)
                         {
                             DateTime now = DateTime.Now;
                             if (member.LockTime.AddMinutes(PassportAuthentication.PasswordAnswerAttemptLockoutDuration) < now)
                             {
                                 bool hasMark = !string.IsNullOrEmpty(mark);
                                 List <DataColumn> columns = new List <DataColumn>(6);
                                 columns.AddRange(new DataColumn[] { "Locked", "LockNum", "LastIp", "LastTime" });
                                 if (hasMark)
                                 {
                                     member.Mark  = mark;
                                     member.Token = Guid.NewGuid();
                                     columns.AddRange(new DataColumn[] { "Mark", "Token" });
                                 }
                                 member.Locked   = false;
                                 member.LockNum  = 0;
                                 member.LastIp   = ip;
                                 member.LastTime = DateTime.Now;
                                 if (member.Update(ds, ColumnMode.Include, columns.ToArray()) == DataStatus.Success)
                                 {
                                     if (hasMark)
                                     {
                                         token = member.Token;
                                     }
                                     result = LoginStatus.Success;
                                 }
                                 else
                                 {
                                     result = LoginStatus.DataError;
                                 }
                             }
                             else
                             {
                                 result = LoginStatus.Locked;
                             }
                         }
                         else
                         {
                             bool hasMark = !string.IsNullOrEmpty(mark);
                             List <DataColumn> columns = new List <DataColumn>(6);
                             columns.AddRange(new DataColumn[] { "LockNum", "LastIp", "LastTime" });
                             if (hasMark)
                             {
                                 member.Mark  = mark;
                                 member.Token = Guid.NewGuid();
                                 columns.AddRange(new DataColumn[] { "Mark", "Token" });
                             }
                             member.LockNum  = 0;
                             member.LastIp   = ip;
                             member.LastTime = DateTime.Now;
                             if (member.Update(ds, ColumnMode.Include, columns.ToArray()) == DataStatus.Success)
                             {
                                 if (hasMark)
                                 {
                                     token = member.Token;
                                 }
                                 result = LoginStatus.Success;
                             }
                             else
                             {
                                 result = LoginStatus.DataError;
                             }
                         }
                     }
                     else
                     {
                         result = LoginStatus.NotApproved;
                     }
                 }
                 else
                 {
                     result = LoginStatus.NotFound;
                 }
             }
             else
             {
                 result = LoginStatus.NeedBind;
             }
             ds.Commit();
             return(result);
         }
         catch (Exception)
         {
             ds.Rollback();
             return(LoginStatus.DataError);
         }
     }
     else
     {
         return(LoginStatus.NotFound);
     }
 }
Esempio n. 3
0
 private static LoginStatus Login(DataSource ds, string name, string password, string ip, string mark, out int errCount, out Member member, out Guid token)
 {
     errCount = PassportAuthentication.MaxInvalidPasswordAttempts;
     member   = null;
     token    = Guid.Empty;
     if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(password))
     {
         ds.Begin();
         try
         {
             LoginStatus result;
             member = Get(ds, name);
             if (member != null)
             {
                 if (member.Approved)
                 {
                     if (password != null)
                     {
                         if (string.Equals(password.MD5(), member.Password))
                         {
                             if (member.Locked)
                             {
                                 DateTime now = DateTime.Now;
                                 if (member.LockTime.AddMinutes(PassportAuthentication.PasswordAnswerAttemptLockoutDuration) < now)
                                 {
                                     bool hasMark = !string.IsNullOrEmpty(mark);
                                     List <DataColumn> columns = new List <DataColumn>(6);
                                     columns.AddRange(new DataColumn[] { "LoginNum", "Locked", "LockNum", "LastIp", "LastTime" });
                                     if (hasMark)
                                     {
                                         member.Mark  = mark;
                                         member.Token = Guid.NewGuid();
                                         columns.AddRange(new DataColumn[] { "Mark", "Token" });
                                     }
                                     member.Locked   = false;
                                     member.LockNum  = 0;
                                     member.LoginNum = member.LoginNum + 1;
                                     member.LastIp   = ip;
                                     member.LastTime = DateTime.Now;
                                     if (member.Update(ds, ColumnMode.Include, columns.ToArray()) == DataStatus.Success)
                                     {
                                         if (hasMark)
                                         {
                                             token = member.Token;
                                         }
                                         result = LoginStatus.Success;
                                     }
                                     else
                                     {
                                         result = LoginStatus.DataError;
                                     }
                                 }
                                 else
                                 {
                                     result = LoginStatus.Locked;
                                 }
                             }
                             else
                             {
                                 bool hasMark = !string.IsNullOrEmpty(mark);
                                 List <DataColumn> columns = new List <DataColumn>(6);
                                 columns.AddRange(new DataColumn[] { "LoginNum", "LockNum", "LastIp", "LastTime" });
                                 if (hasMark)
                                 {
                                     member.Mark  = mark;
                                     member.Token = Guid.NewGuid();
                                     columns.AddRange(new DataColumn[] { "Mark", "Token" });
                                 }
                                 member.LockNum  = 0;
                                 member.LastIp   = ip;
                                 member.LoginNum = member.LoginNum + 1;
                                 member.LastTime = DateTime.Now;
                                 if (member.Update(ds, ColumnMode.Include, columns.ToArray()) == DataStatus.Success)
                                 {
                                     if (hasMark)
                                     {
                                         token = member.Token;
                                     }
                                     result = LoginStatus.Success;
                                 }
                                 else
                                 {
                                     result = LoginStatus.DataError;
                                 }
                             }
                         }
                         else
                         {
                             if (member.Locked)
                             {
                                 result = LoginStatus.Locked;
                             }
                             else
                             {
                                 member.LockNum  = member.LockNum + 1;
                                 member.Locked   = member.LockNum >= PassportAuthentication.MaxInvalidPasswordAttempts;
                                 member.LockTime = DateTime.Now;
                                 member.Update(ds, ColumnMode.Include, "Locked", "LockNum", "LockTime");
                                 errCount = PassportAuthentication.MaxInvalidPasswordAttempts - member.LockNum;
                                 if (errCount < 0)
                                 {
                                     errCount = 0;
                                 }
                                 result = LoginStatus.PasswordError;
                             }
                         }
                     }
                     else
                     {
                         result = LoginStatus.PasswordError;
                     }
                 }
                 else
                 {
                     result = LoginStatus.NotApproved;
                 }
             }
             else
             {
                 result = LoginStatus.NotFound;
             }
             ds.Commit();
             return(result);
         }
         catch (Exception)
         {
             ds.Rollback();
             return(LoginStatus.DataError);
         }
     }
     else
     {
         return(LoginStatus.PasswordError);
     }
 }