예제 #1
0
        public IHttpActionResult Authenticate(LoginRequest login)
        {
            if (login == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            Usuario usuario = null;

            usuario = db.Usuario.Where(x => x.NombreUsuario == login.username).First();

            if (usuario == null)
            {
                return(NotFound());
            }

            using (MD5 md5Hash = MD5.Create())
            {
                var    md5        = new Md5Encrypt();
                string contraseña = md5.GetMd5Hash(md5Hash, login.password);

                bool isCredentialValid = (contraseña.ToUpper() == usuario.Contraseña);
                if (isCredentialValid)
                {
                    var token = TokenGenerator.GenerateTokenJwt(login.username);
                    return(Ok(token));
                }
                else
                {
                    return(Unauthorized());
                }
            }
        }
예제 #2
0
        public IHttpActionResult Authenticate(LoginRequest login)
        {
            if (login == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            if (Membership.ValidateUser(login.Username, login.Password))
            {
                var token = TokenGenerator.GenerateTokenJwt(login.Username);
                return(Ok(token));
            }
            else
            {
                return(Unauthorized());
            }
        }
예제 #3
0
        public IHttpActionResult Authenticate(BOUser login)
        {
            if (login == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            //TODO: Validate credentials Correctly, this code is only for demo !!
            BusinessResult result = CoreFactory.Instance.UserLogin(login);

            if (result.Success)
            {
                var token = TokenGenerator.GenerateTokenJwt(login.Email);
                return(Ok(token));
            }
            else
            {
                return(Unauthorized());
            }
        }