Ejemplo n.º 1
0
        public UserAccount User_Validate(string username, string password)
        {
            try
            {
                IUserRepository userrep = new EntityUserRepository();
                User user = userrep.ValidateUser(username, password);
                if (user == null)
                    return null;

                IAccountRepository acctrep = new EntityAccountRepository();
                Account acct = acctrep.GetAccount(user.AccountID);
                if (acct == null || !acct.IsActive)
                    return null;

                UserAccount useracct = new UserAccount();
                useracct.UserID = user.UserID;
                useracct.Username = user.Username;
                useracct.FirstName = user.FirstName;
                useracct.LastName = user.LastName;
                useracct.EmailAddress = user.EmailAddress;
                useracct.IsAdmin = user.IsAdmin;
                useracct.UserIsActive = user.IsActive;
                useracct.AccountID = acct.AccountID;
                useracct.AccountName = acct.AccountName;
                useracct.AccountDescription = acct.AccountDescription;
                useracct.FTPServer = acct.FTPServer;
                useracct.FTPUsername = acct.FTPUsername;
                useracct.FTPPassword = acct.FTPPassword;
                useracct.AccountIsActive = acct.IsActive;

                return useracct;
            }
            catch
            {
                return null;
            }
        }
Ejemplo n.º 2
0
        private string ValidateInput(User user, string confirmpassword, bool isEdit, bool passwordchanged)
        {
            if (user.AccountID == 0)
                return "Account ID is not valid.";

            if (String.IsNullOrEmpty(user.Username))
                return "Username is required.";

            if (user.Username.Length < 6)
                return "Username must be at least 6 characters.";

            if (!isEdit)
            {
                IUserRepository urep = new EntityUserRepository();
                User usercheck = urep.GetUserByUsername(user.Username);
                if (usercheck != null)
                    return "This username already exists.";
            }

            if (String.IsNullOrEmpty(user.Password))
                return "Password is required.";

            if (!isEdit || (isEdit && passwordchanged))
            {
                if (user.Password != confirmpassword)
                    return "Passwords do not match.";

                if (user.Password.Length < 6)
                    return "Password must be at least 6 characters.";
            }

            if (String.IsNullOrEmpty(user.FirstName) || String.IsNullOrEmpty(user.LastName))
                return "First Name and Last Name are required.";

            if (String.IsNullOrEmpty(user.EmailAddress))
                return "Email address is required.";

            Regex regex = new Regex(@"^[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$");
            if (!regex.IsMatch(user.EmailAddress))
                return "Email address is invalid.";

            return String.Empty;
        }