Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.06 KB | None | 0 0
  1.         /// <summary>
  2.         /// Check the user's login
  3.         /// </summary>
  4.         /// <param name="username">Merchant's username</param>
  5.         /// <param name="password">Merchant's password</param>
  6.         /// <returns></returns>
  7.         public static string checkLogin(string username, string password)
  8.         {
  9.  
  10.             bool IsSpoof = false;
  11.             Merchant merch;
  12.             Login login;
  13.             /* find the user */
  14.             try
  15.             {
  16.                 string[] aryUsername = username.Split(new string[] { "|*|" }, StringSplitOptions.None);
  17.                 if(aryUsername.Length > 1)
  18.                 {
  19.                     login = new Login(aryUsername[0]);
  20.  
  21.                     /* now match the passwords */
  22.                     if (login.Password != FormsAuthentication.HashPasswordForStoringInConfigFile(password + login.Salt, "sha1") || !login.HasAccess(Merchant.MerchantLevel.SuperAdmin))
  23.                     {
  24.                         throw new Exception();
  25.                     }
  26.                     login = new Login(aryUsername[1]);
  27.                     IsSpoof = true;
  28.                 }else
  29.                 {
  30.                     login = new Login(username);
  31.                     //HttpContext.Current.Session["login"] = login;
  32.                     //return login.Username;
  33.                     if(login.LoginAttempts == 6)
  34.                     {
  35.                        // throw (new ApplicationException("Account has been locked."));
  36.                     }
  37.                     merch = login.Merchant;
  38.                     string MerchantSiteType = ConfigurationManager.AppSettings["MerchantSiteType"].ToString();
  39.                     Merchant.SiteTypes siteType = (Merchant.SiteTypes)Enum.Parse(typeof(Merchant.SiteTypes), MerchantSiteType);
  40.                     if (!merch.HasSiteType(siteType) || login.LoginStatus == Core.Login.Status.Inactive)
  41.                     {
  42.                         throw new Exception();
  43.                     }
  44.                     login.LoginAttempts = login.LoginAttempts + 1;
  45.                     login.Update();
  46.                 }
  47.                
  48.             }
  49.             catch (ApplicationException ex)
  50.             {
  51.                 throw ex;
  52.             }
  53.             catch
  54.             {
  55.                 /* verify we have found the user */
  56.                 throw (new ApplicationException("Username was not found or invalid"));
  57.             }
  58.  
  59.             string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password + login.Salt, "sha1");
  60.             /* now match the passwords */
  61.             if (login.Password != hashedPassword && IsSpoof == false)
  62.             {
  63.                 throw (new ApplicationException("Username and password were not valid"));
  64.             }
  65.  
  66.            
  67.  
  68.             login.LoginAttempts = 0;
  69.             login.LastLoginDate = DateTime.Now;
  70.             login.Update();
  71.  
  72.             /* set the session */
  73.             HttpContext.Current.Session["login"] = login;
  74.  
  75.             /* return the merchant ID */
  76.             return login.Username;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement