public async Task <IActionResult> ResetPassword([FromBody] int id) { if (!ModAuthorization()) { return(Unauthorized()); } Customer UserEntry = database.Customer.FirstOrDefault(x => x.Id == id); if (UserEntry == null) { return(NotFound()); } //create the random new PW char[] chars = new char[62]; chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray(); byte[] data; using (RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider()) { data = new byte[10]; crypto.GetBytes(data); } StringBuilder result = new StringBuilder(10); foreach (byte b in data) { result.Append(chars[b % (chars.Length)]); } UserEntry.Pw = result.ToString(); await LogAction("reset the password of an user", UserEntry.Id, UserEntry.Login); database.Update(UserEntry); await database.SaveChangesAsync(); return(Ok(JsonConvert.SerializeObject(result.ToString()))); // stupid but we have to return to know it somehow for now }