Exemplo n.º 1
0
        public ActionResult Login([FromBody] TUser user)
        {
            Dictionary <string, string> keyPair = GetRSAKeyPair();
            var password = EncryptionProvider.DecryptRSA(user.Password, keyPair["PRIVATE"]);

            if (userService.VerifyUser(user.UserName, password))
            {
                return(Ok <string>(JwtManager.GenerateToken(user.UserName)));
            }
            else
            {
                return(StatusCode(System.Net.HttpStatusCode.Unauthorized));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ModifyPassword([FromBody] TUser user)
        {
            if (user == null || string.IsNullOrEmpty(user.Password) || string.IsNullOrEmpty(user.NewPassword))
            {
                return(StatusCode(HttpStatusCode.BadRequest));
            }

            Dictionary <string, string> keyPair = GetRSAKeyPair();

            user.Password    = EncryptionProvider.DecryptRSA(user.Password, keyPair["PRIVATE"]);
            user.NewPassword = EncryptionProvider.DecryptRSA(user.NewPassword, keyPair["PRIVATE"]);

            var result = await userService.ModifyPassword(user);

            return(result ? Ok() : StatusCode(HttpStatusCode.InternalServerError));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Register([FromBody] TUser user)
        {
            if (user == null || string.IsNullOrEmpty(user.RegEmall))
            {
                return(StatusCode(HttpStatusCode.BadRequest));
            }
            string verifyCode = "";

            if (string.IsNullOrEmpty(user.NewPassword) || !cache.TryGetValue(user.RegEmall, out verifyCode) || string.IsNullOrEmpty(verifyCode) || 0 != user.NewPassword.Trim().CompareTo(verifyCode))
            {
                return(StatusCode(HttpStatusCode.Unauthorized));
            }

            Dictionary <string, string> keyPair = GetRSAKeyPair();

            //解密登录密码
            user.Password = EncryptionProvider.DecryptRSA(user.Password, keyPair["PRIVATE"]);
            var result = await userService.Register(user);

            return(result ? Ok() : StatusCode(HttpStatusCode.InternalServerError));
        }