コード例 #1
0
ファイル: LoginService.cs プロジェクト: raimonomiar/practice
        public UserModel GetUserDetails(UserModel model)
        {
            try
            {
                var userModel = new UserModel();

                var user = unitOfWork.UserRepository.Get(x => x.LoginId.ToLower() == model.LoginId.ToLower()).FirstOrDefault();

                if (user != null)
                {
                    using (MD5 md5Hash = MD5.Create())
                    {
                        if (HashPassword.VerifyMd5Hash(md5Hash, model.Password, user.Password))
                        {
                            user = unitOfWork.UserRepository.Get(x => (x.LoginId == model.LoginId && x.Password == user.Password)).FirstOrDefault();

                            if (user != null)
                            {
                                userModel = Mapper.UserMapper.UserDbToUserModel(user);
                            }

                            return(userModel);
                        }
                    }
                }

                return(userModel);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);

                return(null);
            }
        }
コード例 #2
0
        public bool checkLogin(string username, string password)
        {
            var user = new Users(username, password);

            user = dbContext.Users.FirstOrDefault(x => x.Username == username);
            return(hashPassword.VerifyMd5Hash(password, user.Password));
        }
コード例 #3
0
ファイル: LoginController.cs プロジェクト: michalSRT/Printo
        public IActionResult Index(User user)
        {
            User account = _context.Users.FirstOrDefault(u => u.Login == user.Login);

            if (account != null)
            {
                if (account.IsActive == false)
                {
                    ModelState.AddModelError("", "Twoje konto zostało dezaktywowane.");
                    return(View());
                }
                else
                if (HashPassword.VerifyMd5Hash(user.Password, account.Password))
                {
                    HttpContext.Session.SetString("UserID", account.UserID.ToString());
                    HttpContext.Session.SetString("UserTypeID", account.UserTypeID.ToString());
                    HttpContext.Session.SetString("Login", account.Login.ToString());
                    HttpContext.Session.SetString("Name", account.Name.ToString());

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Błędne hasło");
                }
                return(View());
            }

            if (account == null)
            {
                ModelState.AddModelError("", "Błędny login");
                return(View());
            }
            else
            {
                return(View());
            }
        }