示例#1
0
 public static bool IsLoginAllowed(Web_Login_datum row, String password)
 {
     // clear errors
     AuthorizeErrors = new List <AuthorizeErrorsEnum>();
     // check no login data
     if (row == null)
     {
         AuthorizeErrors.Add(AuthorizeErrorsEnum.NoLoginData);
     }
     // cehck is suspended
     if (row != null && row.Suspended == true)
     {
         AuthorizeErrors.Add(AuthorizeErrorsEnum.LoginSuspended);
     }
     // check is email confirmed
     if (row != null && row.Email_Confirmed == false)
     {
         AuthorizeErrors.Add(AuthorizeErrorsEnum.EmailNotConfirmed);
     }
     // check if password is verified
     if (row != null && PasswordVerify.VerifyHashedPassword(row.Password, row.Salt, password) == PasswordVerify.Failed)
     {
         AuthorizeErrors.Add(AuthorizeErrorsEnum.PasswordNotVerified);
     }
     return(!GetAuthorizeErrors().Any()); // true if no errors
 }
示例#2
0
        public static bool ResetPassword(string email, string password, EntityContext dbContext = null)
        {
            dbContext.CheckInit();

            var lowerEmail = email.ToLower();
            var loginData  = dbContext.Web_Login_Data.FirstOrDefault(p =>
                                                                     p.Investigator.Email_Address.ToLower() == lowerEmail
                                                                     );

            if (loginData == null)
            {
                return(false);
            }
            loginData.Password = PasswordVerify.HashPassword(password, loginData.Salt);
            try { dbContext.SaveChanges(); } catch (Exception ex) { return(false); }

            return(true);
        }
        public static CachedUser MakeNewUserLogin(String username, String email, String password, EntityContext e = null)
        {
            e.CheckInit();
            if (!Authorize.EmailExists(email, e))
            {
                return(null);
            }
            if (Authorize.EmailIsRegistered(email, e))
            {
                return(null);
            }
            if (Authorize.UsernameIsRegistered(username, e))
            {
                return(null);
            }
            var lowerEmail = email.ToLower();

            try
            {
                var investigator = e.Investigators.FirstOrDefault(p => p.Email_Address.ToLower() == lowerEmail);
                var loginData    = investigator.Web_Login_Data;
                var salt         = Encrypt.GenerateSalt();
                loginData = new Web_Login_datum()
                {
                    Investigator      = investigator,
                    Salt              = salt,
                    Password          = PasswordVerify.HashPassword(password, salt),
                    Temp_Password     = false,
                    Investigator_Name = investigator.Investigator_Name,
                    Username          = username,
                    Suspended         = false,
                    Email_Confirmed   = false,
                    DataSource        = DATA_SOURCE_NAME
                };
                e.Web_Login_Data.Add(loginData);
                e.SaveChanges();
                return(GetCachedUser.GetNew(loginData));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }