Пример #1
0
        public bool VerifyLogin(User user)
        {
            using (var dc = new DataContext())
            {
                var checkUser = dc.Users.SingleOrDefault(i => i.username == user.username && i.pass == user.pass);
                if (checkUser != null) SessionVar.Set("userData", new UserData(user));

                return checkUser != null;
            }
        }
Пример #2
0
        public bool VerifySignup(User user, string repass)
        {
            if (string.IsNullOrEmpty(user.username) || string.IsNullOrEmpty(user.pass) || string.IsNullOrEmpty(user.email))
                return false;

            if (user.pass != repass)
            {
                return false;
            }
            if (user.age < 18)
            {
                return false;
            }

            //Username must start with a letter or number - Cannot contain two consecutive symbols - Must consist of between 3 to 15 allowed characters
            if (!Regex.IsMatch(user.username, @"^(?=[A-Za-z0-9])(?!.*[._()\[\]-]{2})[A-Za-z0-9._()\[\]-]{3,15}$"))
            {
                return false;
            }

            //Password must be minimum 8 characters at least 1 Alphabet and 1 Number
            if (!Regex.IsMatch(user.pass, @"^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$"))
            {
                return false;
            }

            try
            {
                var verEmail = new MailAddress(user.email);
            }
            catch (FormatException)
            {
                return false;
            }

            using (var dc = new DataContext())
            {
                var existuser = dc.Users.SingleOrDefault(i => i.username == user.username || i.email == user.email);
                if (existuser != null) return false;

                user.userid = Guid.NewGuid();
                user.pass = Hash.HexSha256(user.pass);
                dc.Users.Add(user);
                dc.SaveChanges();
                return true;
            }
        }