Example #1
0
        //Додати валідацію даних!!!
        public bool Register(RegisterModel registerUser)
        {
            if (registerUser != null)
            {
                if (db.Users.Any(e => e.Name == registerUser.Login))
                {
                    return(false);
                }
                else
                {
                    UserModel user = new UserModel();

                    user.Age       = registerUser.Age;
                    user.Name      = registerUser.Login;
                    user.PassWord  = SHA.GetPasswordHashWithSalt(registerUser.Login, registerUser.Password);
                    user.Sex       = (int)registerUser.Sex;
                    user.ImageUser = registerUser.ImageLink;
                    user.Role      = db.Roles.Where(e => e.RoleType == RoleTypes.Authorized_LOW_Access).FirstOrDefault();
                    db.Users.Add(user);
                    db.SaveChanges();

                    string pass = SHA.GetPasswordHashWithSalt(registerUser.Login, registerUser.Password);
                    user = db.Users.Where(e => e.Name == registerUser.Login && e.PassWord == pass).FirstOrDefault();
                    if (user != null)
                    {
                        FormsAuthentication.SetAuthCookie(registerUser.Login, true);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        public UserModel SignIn(SignIn signIn)
        {
            string pass = SHA.GetPasswordHashWithSalt(signIn.Login, signIn.Password);

            return(db.Users.FirstOrDefault(e => e.Name == signIn.Login && e.PassWord == pass));
        }