Exemplo n.º 1
0
        public async Task <IActionResult> Create(User model, string Password2)
        {
            //입력체크
            if (!ModelState.IsValid)
            {
                return(Ok(2));                     //2:실패
            }
            //비번확인용 체크
            if (model.Password != Password2)
            {
                return(Ok(2));//비번과 비번확인 틀림
            }
            //아이디 중복체크
            if (await _repository.ReadOneAsync(model.Email) != null)
            {
                return(Ok(3));//3:아이디중복
            }
            else
            {
                //계정등록에 문제없음
                model.Password = CryptorEngine.EncryptPassword(model.Password); //해쉬 암호화
                await _repository.CreateAsync(model);

                //쿠키삭제
                await HttpContext.SignOutAsync("Cookies");

                //쿠키생성
                var ci = Cookie.GetClaimsIdentity(model.Id.ToString(), model.Email, model.Role);
                await HttpContext.SignInAsync("Cookies", new ClaimsPrincipal(ci)); //AuthenticationProperties를 안 넣으니까 session이 됨
            }
            return(Ok(1));                                                         //1:성공
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Login(User model, bool rememberme)
        {
            var result = 1; //성공

            //입력체크
            if (!ModelState.IsValid)
            {
                return(Ok(2));
            }

            //계정검색
            var user = await _repository.ReadOneAsync(model.Email);

            if (user == null)
            {
                return(Ok(2)); //실패
            }
            //Lock체크
            if (user.Lock >= 5)
            {
                return(Ok(3)); //락
            }
            //비밀번호체크
            if (!user.Password.Equals(CryptorEngine.EncryptPassword(model.Password))) //해쉬 복호화
            {
                user.Lock++;                                                          //실패
                result = 2;
            }
            else //로그인에 문제없음
            {
                user.Lock = 0;
                //쿠키삭제
                await HttpContext.SignOutAsync("Cookies");

                //쿠키생성
                var ci = Cookie.GetClaimsIdentity(user.Id.ToString(), user.Email, user.Role);
                if (rememberme)
                {
                    AuthenticationProperties authProperties = new AuthenticationProperties
                    {
                        IsPersistent = true,
                        ExpiresUtc   = DateTime.UtcNow.AddMinutes(60)                                  //60분 로그인정보 기억
                    };
                    await HttpContext.SignInAsync("Cookies", new ClaimsPrincipal(ci), authProperties); //아래 cookie~긴 거랑 "Cookies"같음
                }
                else
                {
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(ci));
                }
            }

            //데이터변경
            await _repository.UpdateAsync(user);

            return(Ok(result)); //성공
        }
Exemplo n.º 3
0
        public void EncryptTest()
        {
            CryptorEngine cryptor = new CryptorEngine();

            string password  = "******";
            string encrypted = cryptor.Encrypt(password, true);

            Console.WriteLine(encrypted); // ????
            string decrypted = cryptor.Decrypt(encrypted, true);

            Console.WriteLine(decrypted);                       // 1234

            Console.WriteLine(cryptor.EncryptPassword("1234")); // ????
        }