public IActionResult Index(LoginRequestModel lrm, DataServices dataServices) { lrm.RequestTime = DateTime.Now; var Users = dataServices.GetUserData(); var user = Users.Where(u => u.Username.Equals(lrm.Username)); if (user == null || !user.Any()) { return(View()); } var userArray = user.ToArray(); if (!PasswordServices.CompareHash(userArray[0].PasswordHash, PasswordServices.HashGen(userArray[0].Salt, lrm.Password))) { return(View()); } var newData = new List <LogDataModel>(); newData.Add(new LogDataModel(userArray[0], DateTime.Now)); dataServices.SaveLogData(newData, false); //TODO: Unlock door return(RedirectToAction(actionName: "Unlocked", controllerName: "Home")); }
public IActionResult CreateUser(NewUserModel newUserModel, DataServices dataServices) { var adminKey = LocalConfigurationServices.GetAdminKey(); if (!newUserModel.AdminKey.Equals(adminKey)) { return(View()); } var salt = PasswordServices.SaltGen(); var newUser = new UserDataModel(newUserModel.Username, newUserModel.Name, PasswordServices.HashGen(salt, newUserModel.Password), salt); var newUserList = new List <UserDataModel>(); newUserList.Add(newUser); dataServices.SaveUserData(newUserList, false); return(RedirectToAction(actionName: "Index", controllerName: "Admin")); }