public VoidOperationContract ResetPassword(ResetPasswordContract contract) { try { using (NeedAGolferDataContext dataContext = new NeedAGolferDataContext()) { var golferRetriever = RetrieverFactory.CreateInterface <IGolferRetriever>(); var golfer = golferRetriever.SelectByUsernameAndEmail(contract.UserAccount, contract.EmailAddress); string salt = PasswordCrypto.GetSalt(); string hashedPassword = PasswordCrypto.ComputeHash(contract.Password, "SHA256", salt); golfer.PasswordHash = hashedPassword; golfer.PasswordSalt = salt; dataContext.Golfers.Attach(golfer, true); dataContext.SubmitChanges(); dataContext.Connection.Close(); return(new VoidOperationContract() { ErrorMessage = "" }); } } catch (Exception ex) { return(new VoidOperationContract() { ErrorMessage = ex.Message }); } }
private string GetHashedPassword(string username, string password) { var saltQueryable = from golfer in dataContext.Golfers where (golfer.ScreenName == username) select golfer.PasswordSalt; if (saltQueryable.Count() == 0) { return(string.Empty); } string salt = saltQueryable.FirstOrDefault(); string hashedPassword = PasswordCrypto.ComputeHash(password, "SHA256", salt); return(hashedPassword); }
public VoidOperationContract CreateGolfer(CreateGolferContract createContract) { VoidOperationContract contract = new VoidOperationContract(); try { using (NeedAGolferDataContext dataContext = new NeedAGolferDataContext()) { var existing = from golfers in dataContext.Golfers where (golfers.ScreenName == createContract.Name || golfers.EmailAddress == createContract.EmailAddress) select golfers; if (existing.Count() == 0) { Golfer golfer = new Golfer(); golfer.EmailAddress = createContract.EmailAddress; golfer.AllowEmails = false; golfer.PhoneNumber = createContract.PhoneNumber; golfer.IsAvailable = true; golfer.Handicap = createContract.Handicap; golfer.Latitude = createContract.Latitude; golfer.Longitude = createContract.Longitude; golfer.LastUpdated = DateTime.Now; golfer.ScreenName = createContract.Name; golfer.AvailabilityDistance = createContract.AvailabilityDistanceInMiles; string salt = PasswordCrypto.GetSalt(); string hashedPassword = PasswordCrypto.ComputeHash(createContract.Password, "SHA256", salt); golfer.PasswordHash = hashedPassword; golfer.PasswordSalt = salt; dataContext.Golfers.InsertOnSubmit(golfer); dataContext.SubmitChanges(); dataContext.Connection.Close(); } else { contract.ErrorMessage = "There is already a user registered with this screen name or email address. Please try again."; } } } catch (Exception ex) { contract.ErrorMessage = ex.Message; } return(contract); }