// POST api/CustomLogin
        public HttpResponseMessage Post(ChangePassRequest changeRequest)
        {
            string shardKey = Sharding.FindShard(User);
            // NEED TO RECHECK CONTEXT MUST DETERMINE COMPANY -> MUST FIND CORRECT DataBase
            mpbdmContext <Guid> context = new mpbdmContext <Guid>(WebApiConfig.ShardingObj.ShardMap, new Guid(shardKey), WebApiConfig.ShardingObj.connstring);
            Account             account = context.Accounts.Include("User").Where(a => a.User.Email == changeRequest.email).SingleOrDefault();

            if (account != null)
            {
                byte[] incoming = CustomLoginProviderUtils.hash(changeRequest.oldpass, account.Salt);

                if (CustomLoginProviderUtils.slowEquals(incoming, account.SaltedAndHashedPassword))
                {
                    if (changeRequest.password == changeRequest.repass)
                    {
                        byte[] newpass = CustomLoginProviderUtils.hash(changeRequest.password, account.Salt);
                        account.SaltedAndHashedPassword = newpass;
                        context.SaveChanges();
                        return(this.Request.CreateResponse(HttpStatusCode.Created));
                    }
                    return(this.Request.CreateResponse(HttpStatusCode.BadRequest, "Passes don't match"));
                }
            }
            return(this.Request.CreateResponse(HttpStatusCode.Unauthorized, "Invalid email or password"));
        }
Beispiel #2
0
        public HttpResponseMessage ChangePass(ChangePassRequest datos)
        {
            var cambioPassDA  = new UsuarioDataAccess();
            var newPassResult = cambioPassDA.ChangePass(datos);

            return(Request.CreateResponse(HttpStatusCode.OK, newPassResult));
        }
        public async Task <RequestResult> ChangePassword(ChangePassRequest request)
        {
            var customer = _context.Customers.Find(request.CustomerId);

            if (customer != null)                                      //Có tồn tại
            {
                if (customer.IsActive == 1)                            //Tài khoản không bị khoá
                {
                    if (customer.Password.Equals(request.OldPassword)) //OldPassword trùng password cũ
                    {
                        if (customer.Password.Equals(request.NewPassword))
                        {
                            return(new RequestResult
                            {
                                StatusCode = DataAccess.Models.Enum.StatusCode.Failed,
                                Content = "New password is the same as old password."
                            });
                        }
                        else
                        {
                            customer.Password = request.NewPassword;
                            _context.Update(customer);
                            _context.SaveChanges();
                            customer = _context.Customers.Find(request.CustomerId);
                            return(new RequestResult
                            {
                                StatusCode = DataAccess.Models.Enum.StatusCode.Success,
                                Content = JsonConvert.SerializeObject(customer)
                            });
                        }
                    }
                    else
                    {
                        return(new RequestResult
                        {
                            StatusCode = DataAccess.Models.Enum.StatusCode.Failed,
                            Content = "Old password is not correct."
                        });
                    }
                }
                else
                {
                    return(new RequestResult
                    {
                        StatusCode = DataAccess.Models.Enum.StatusCode.Failed,
                        Content = "Account is deactivated."
                    });
                }
            }
            else
            {
                return(new RequestResult
                {
                    StatusCode = DataAccess.Models.Enum.StatusCode.Failed,
                    Content = "Invalid information."
                });
            }
        }
Beispiel #4
0
        public ActionResult ChangePass(ChangePassRequest model)
        {
            var response = _UserService.ChangePass(model);

            if (response == null)
            {
                return(BadRequest("Old password wrong"));
            }

            return(Ok(response));
        }
Beispiel #5
0
        public async Task <L2Response> ChangePassword(string username, string currentPass, string newPass)
        {
            var changePassRequest = new ChangePassRequest
            {
                Username        = username,
                CurrentPassword = currentPass,
                NewPassword     = newPass
            };

            var responseObject = await changePassRequest.SendPostRequest <L2Response>();

            return(responseObject);
        }
Beispiel #6
0
        public ActionResult ChangePassword([FromForm] ChangePassRequest model)
        {
            string userId = (HttpContext.Items["User"] as User).Id;

            if (userId != model.Id)
            {
                return(StatusCode(403, new { message = "Forbidden" }));
            }
            var res = _accountService.ChangePassword(model);

            if (!res.Item1)
            {
                return(BadRequest(new { message = res.Item2 }));
            }
            return(Ok(new { message = "Thay đổi mật khẩu thành công" }));
        }
        //METODO CAMBIO CONTRASEÑA
        public ChangePassResponse ChangePass(ChangePassRequest datos)
        {
            try
            {
                using (var context = new BDReservasEntities())
                {
                    ObjectParameter RETCODE = new ObjectParameter("RETCODE", typeof(int));
                    ObjectParameter MENSAJE = new ObjectParameter("MENSAJE", typeof(string));

                    context.PA_CAMBIO_PASSWORD(
                        datos.Id_usuario,
                        datos.Oldpass,
                        datos.Newpass,
                        RETCODE, MENSAJE
                        );

                    if ((int)RETCODE.Value < 0)
                    {
                        throw new Exception("Error no controlado");
                    }

                    if ((int)RETCODE.Value > 0)
                    {
                        throw new Exception(MENSAJE.Value.ToString());
                    }

                    return(new ChangePassResponse()
                    {
                        Retcode = (int)RETCODE.Value,
                        Mensaje = MENSAJE.Value.ToString().Trim()
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ChangePassResponse()
                {
                    Mensaje = ex.Message.Trim(),
                    Retcode = -1
                });
            }
        }
Beispiel #8
0
        public override void BuildPacket()
        {
            base.BuildPacket();
            var changePassRequest = new ChangePassRequest
            {
                user_id  = GlobalVariables.CurrentUser.UserID,
                new_pass = NewPassword,
                old_pass = OldPassword
            };

            byte[] packetData;
            using (var stream = new MemoryStream())
            {
                Serializer.Serialize(stream, changePassRequest);
                packetData = stream.ToArray();
            }
            GlobalVariables.CountRequest++;
            Packet = StoreConnection.BuildServerPacket(packetData.Length + 16, (int)MessageType.Type.USER_CHANGE_PASS, 2,
                                                       packetData, GlobalVariables.CountRequest);
        }
Beispiel #9
0
    public void ChangePassword()
    {
        if (Panel != null)
        {
            bool isActive = Panel.activeSelf;
            Panel.SetActive(!isActive);
        }

        var newPass            = newPassInput.GetComponent <InputField>().text;
        ChangePassRequest req  = new ChangePassRequest("changePassword", Global.getID(), Global.getToken(), newPass);
        string            json = JsonConvert.SerializeObject(req);

        Byte[] data = System.Text.Encoding.ASCII.GetBytes(json);

        Global.stream.Write(data, 0, data.Length);
        data = new Byte[256];
        string responseData = string.Empty;

        Int32 bytes = Global.stream.Read(data, 0, data.Length);

        responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    }
Beispiel #10
0
        public Tuple <bool, string> ChangePassword(ChangePassRequest model)
        {
            var user = _userService.Get(model.Id);

            if (user == null)
            {
                return(new Tuple <bool, string>(false, "User không tồn tại"));
            }
            if (user.Username != model.UserName)
            {
                return(new Tuple <bool, string>(false, "Username không chính xác"));
            }
            var passHash = Helpers.Md5Hash(model.OldPassword);

            // var md5 = new MD5CryptoServiceProvider();
            // var passHash = Encoding.ASCII.GetString(md5.ComputeHash(Encoding.ASCII.GetBytes(model.OldPassword)));
            if (user.PasswordHash.Equals(passHash))
            {
                var res = new Tuple <bool, string>(_userService.ResetPass(model.Id, model.NewPassword), "");
                return(res);
            }
            return(new Tuple <bool, string>(false, "Mật khẩu cũ không chính xác"));
        }
        public string ChangePass(ChangePassRequest model)
        {
            var user = _Users.Find(x => x.Id == model.id).SingleOrDefault();

            if (user == null)
            {
                return(null);
            }


            bool verified = BC.Verify(model.old, user.password);

            if (!verified)
            {
                return(null);
            }

            user.password = BC.HashPassword(model.password);

            _Users.ReplaceOne(sub => sub.Id == model.id, user);


            return(generateJwtToken(user));
        }