public static void AddUser(User user) { string password = Convert.ToBase64String(user.Password.Hash); string salt = Convert.ToBase64String(user.Password.Salt.ToByteArray()); StringBuilder commandText = new StringBuilder(); commandText.AppendLine("INSERT INTO Users VALUES ("); commandText.AppendLine("'" + user.Username + "',"); commandText.AppendLine("'" + password + "',"); commandText.AppendLine("'" + salt + "'"); commandText.AppendLine(");"); SQLiteCommand command = new SQLiteCommand(); command.Connection = Connection; command.CommandText = commandText.ToString(); command.ExecuteNonQuery(); command.Dispose(); }
public static bool TryGetUser(string username, out User user) { if (UsernameExists(username)) { StringBuilder commandText = new StringBuilder(); commandText.AppendLine("SELECT Password, Salt"); commandText.AppendLine("FROM Users"); commandText.AppendLine("WHERE Username = '******';"); SQLiteCommand command = new SQLiteCommand(); command.Connection = Connection; command.CommandText = commandText.ToString(); SQLiteDataReader reader = command.ExecuteReader(); reader.Read(); string passwordText = reader.GetString(0); string saltText = reader.GetString(1); byte[] hash = Convert.FromBase64String(passwordText); Guid salt = new Guid(Convert.FromBase64String(saltText)); user = new User(); user.Username = username; user.Password = new Password(hash, salt); reader.Close(); command.Dispose(); return true; } else { user = null; return false; } }
public Home(User user) { InitializeComponent(); #region Test Code user.Files = new List<Deposit>(); user.Files.Add(new Deposit()); user.Files[0].Directory = "C:\\Users\\Bob\\Documents"; user.Files[0].FileName = "Notes"; user.Files[0].Extension = ".txt"; user.Files[0].IsEncrypted = true; user.Files.Add(new Deposit()); user.Files[1].Directory = "C:\\Users\\Bob\\Pictures"; user.Files[1].FileName = "Scenery"; user.Files[1].Extension = ".jpg"; user.Files[1].IsEncrypted = false; user.Files.Add(new Deposit()); user.Files[2].Directory = "C:\\Users\\Bob\\Music"; user.Files[2].FileName = "House Of Rock"; user.Files[2].Extension = ".mp3"; user.Files[2].IsEncrypted = true; user.Files.Add(new Deposit()); user.Files[3].Directory = "C:\\Users\\Bob\\Documents"; user.Files[3].FileName = "Budget"; user.Files[3].Extension = ".xlsx"; user.Files[3].IsEncrypted = true; user.Files.Add(new Deposit()); user.Files[4].Directory = "C:\\Users\\Bob\\Documents"; user.Files[4].FileName = "Notes"; user.Files[4].Extension = ".txt"; user.Files[4].IsEncrypted = false; user.Files.Add(new Deposit()); user.Files[5].Directory = "C:\\Users\\Bob\\Pictures"; user.Files[5].FileName = "Vacation"; user.Files[5].Extension = ".jpg"; user.Files[5].IsEncrypted = false; user.Files.Add(new Deposit()); user.Files[6].Directory = "C:\\Users\\Bob\\Desktop"; user.Files[6].FileName = "Speech"; user.Files[6].Extension = ".mp4"; user.Files[6].IsEncrypted = true; user.Files.Add(new Deposit()); user.Files[7].Directory = "C:\\Users\\Bob\\"; user.Files[7].FileName = "Meeting Minutes"; user.Files[7].Extension = ".docx"; user.Files[7].IsEncrypted = true; #endregion profile = user; EncryptedFileCabinet.ItemsSource = encryptedFiles; DecryptedFileCabinet.ItemsSource = decryptedFiles; }