示例#1
0
        public async Task <HttpResponseMessage> ChangePassword([FromBody] ChangePasswordModel model)
        {
            try
            {
                //ユーザーID、パスワードによる認証
                var ldapUser = await new LdapUserStore().Authenticate(model.Id, model.OldPassword);
                if (ldapUser == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }

                //パスワードをハッシュ化
                var passwordHash = SSHASaltedGenerator.GenerateSaltedSHA1(model.NewPassword);

                //パスワードを更新
                await new LdapUserStore().SetPasswordHashAsync(ldapUser, passwordHash);

                //更新した結果を返す
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e));
            }
        }
示例#2
0
        public async Task <HttpResponseMessage> SetPassword([FromBody] SetPasswordModel model)
        {
            try
            {
                //該当ユーザーを取得
                var ldapUser = await new LdapUserStore().FindByNameAsync(model.Id);

                //パスワードをハッシュ化
                var passwordHash = SSHASaltedGenerator.GenerateSaltedSHA1(model.Password);

                //パスワードを更新
                await new LdapUserStore().SetPasswordHashAsync(ldapUser, passwordHash);

                //更新した結果を返す
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e));
            }
        }