/// <summary> /// Function for attempting to log in the user /// </summary> /// <param name="parameter"> Password Box </param> /// <returns> returns the user information needed for the program </returns> private UserDTO login(IHavePassword parameter) { PasswordHelper passwordHelper = new PasswordHelper(); if (parameter != null) { //Grab the Secure String from the password container object var secureString = parameter.Password; if (string.IsNullOrWhiteSpace(email)) { informationText = "Enter your email"; } else if (secureString.Length == 0) { informationText = "Enter your password"; } else { //Grab the User DTO data UserLoginCredentialsDTO userDTO = _serviceProxy.GetUserLoginCredentials(email); if (userDTO == null) { informationText = "User does not exist"; return(null); } //Unsecure the password object and compare against the database salt and password hash if (userDTO.PasswordHash == passwordHelper.GenerateSHA256String(passwordHelper.ConvertToUnsecureString(secureString) + userDTO.Salt)) { //login success try { return(_serviceProxy.GetUser(email)); } catch (Exception e) { informationText = "There was a problem accessing the database"; Console.WriteLine(e); } } else { informationText = "Incorrect password"; } } } return(null); }
private async void signin(object o) { if (UserName == "" || Password.Length == 0) { LoginMessage = "Please enter a username or password"; } else { LoginMessage = "Logging in...please wait"; if (ClientLogin == null) { throw new InvalidClientLoginException("No ClientLogin assigned."); } ClientLogin.Password = PasswordHelper.ConvertToUnsecureString(Password); ClientLogin.Username = UserName; // this might take a while so we need a task or else ui wont update Task <bool> logging = Task.Run(() => ClientLogin.login()); bool isloggedin = await logging; /* * Thread t = new Thread(new ThreadStart(delegate * { * ClientLogin.login(); * }));*/ if (isloggedin) { Console.WriteLine("Client found!"); resetForm(); LoginSuccess(ClientLogin.Client); } else { LoginMessage = "Username or password incorrect!"; } } }
/// <summary> /// Creates a new user /// </summary> /// <param name="parameter"> Password Box </param> private void createAccount(IHavePassword parameter) { PasswordHelper passwordHelper = new PasswordHelper(); if (parameter != null) { //Grab the Secure String from the password container object var secureString1 = parameter.Password; var secureString2 = parameter.ConfirmPassword; if (string.IsNullOrWhiteSpace(email)) { informationText = "Enter an email"; } else if (string.IsNullOrWhiteSpace(firstName)) { informationText = "Enter a first name"; } else if (string.IsNullOrWhiteSpace(lastName)) { informationText = "Enter a last name"; } else if (string.IsNullOrWhiteSpace(employeeType)) { informationText = "Select an employee type"; } else if (secureString1.Length == 0) { informationText = "Enter your password"; } else if (secureString2.Length == 0) { informationText = "Confirm your password"; } else { try { if (_serviceProxy.checkDuplicateUser(email)) { informationText = "This email already has an account"; } else if (!passwordHelper.ConvertToUnsecureString(secureString1).Equals(passwordHelper.ConvertToUnsecureString(secureString2))) { informationText = "Passwords do not match"; } else { byte[] salt = getSalt(32); User user = new User { Email = email, FirstName = firstName, LastName = lastName, EmployeeType = employeeType, Salt = salt, PasswordHash = passwordHelper.GenerateSHA256String(passwordHelper.ConvertToUnsecureString(secureString1) + salt) }; _serviceProxy.addUser(user); informationText = "User added"; } } catch (Exception e) { informationText = "There was a problem accessing the database"; Console.WriteLine(e); } } } }