public bool CreateUser(string username, string password, RoleType roleType) { AddRoles(); var user = new User { Username = username, Password = PasswordEncoder.EncodeMd5(password) }; switch (roleType) { case RoleType.ADMIN: user.Roles.Add(FindRoleBy(RoleType.ADMIN)); user.Roles.Add(FindRoleBy(RoleType.STANDARD)); break; case RoleType.STANDARD: user.Roles.Add(FindRoleBy(RoleType.STANDARD)); break; } user.Roles.Add(FindRoleBy(RoleType.WORKER)); try { Database.Users.Add(user); Database.SaveChanges(); return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(false); }
public void Submit() { var loggedUser = StateManager.UserSession.SessionEntity; var oldP = Form.OldPassword; var newPass = Form.NewPassword; var confPass = Form.NewPasswordConf; if (PasswordEncoder.EncodeMd5(oldP) != loggedUser.Password) { Form.Log(WrongPasswordMsg); return; } if (newPass != confPass) { Form.Log(PasswordsDoNotMatchMsg); return; } if (!StateManager.UserService.IsInfoValid(loggedUser.Username, newPass)) { Form.Log(InvalidPasswordMsg); return; } StateManager.Push(new ConfirmActionPresenter(StateManager, OnConfirmAction, $"Промяна на паролата на потребител {loggedUser.Username}?")); }
private void SaveUser() { var user = StateManager.UserSession.SessionEntity; user.Password = PasswordEncoder.EncodeMd5(Form.NewPassword); StateManager.UserService.Save(user); Cancel(); }
public void LoginAction() { var username = Form.Username; var password = Form.Password; if (password == null || username == null || username == "" || password.Length < 6) { Form.Log(InvalidUserPassword); return; } var user = StateManager.UserService.FindByUsername(username); if (user == null) { Form.Log(InvalidUsername); Form.Username = ""; return; } var hashedPassword = PasswordEncoder.EncodeMd5(password); if (user.Password != hashedPassword) { Form.Log(InvalidPassword); Form.Password = ""; return; } if (!user.IsEnabled) { Form.Log(UserIsDisabled); return; } LoggedUser = user; StateManager.UserSession.SessionEntity = user; StateManager.Pop(); }