Пример #1
0
        public UserData(User user)
        {
            if (user == null) return;

            userid = user.userid;
            username = user.username;
            age = user.age;
            email = user.email;
        }
Пример #2
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;
            }
        }
Пример #3
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;
            }
        }
Пример #4
0
        public ActionResult Login(string username, string password)
        {
            if (!ModelState.IsValid) return null;

            var objUserData = SessionVar.Get<UserData>("userData");
            if (objUserData != null) return null;

            var user = new User {
                username = username,
                pass = Hash.HexSha256(password)
            };

            return Json(new
            {
                successLogin = _userLogic.VerifyLogin(user)
            });
        }
Пример #5
0
        public ActionResult Signup(string username, string password, string repassword, string age, string email)
        {
            var objUserData = SessionVar.Get<UserData>("userData");
            if (objUserData != null) return null;

            try{
                var user = new User {
                    username = username,
                    pass = password,
                    age = Convert.ToInt32(age),
                    email = email
                };

                return Json(new {
                    successSignup = _userLogic.VerifySignup(user, repassword)
                });
            }
            catch (Exception e)
            {
                //TODO:: ERROR LOG!
                Console.WriteLine("Error occured: " + e);
                return null;
            }
        }