private const string FILE_NAME = "ARCHIVE.csr"; //store the password in a .csr file public void Store(PasswordArchive user) //store the user { var bf = new BinaryFormatter(); var outfile = new FileStream(FILE_NAME, FileMode.Append, FileAccess.Write); for (var i = 0; i < user.Passwords.Count; i++) { user.Passwords[i] = EncodeToBase64(user.Passwords[i]); } if (!File.Exists(FILE_NAME)) { outfile = new FileStream(FILE_NAME, FileMode.Create, FileAccess.Write); } bf.Serialize(outfile, user); outfile.Close(); System.Console.WriteLine("Successfully wrote user to file."); }
public PasswordArchive LoadUser(string userName) //load a single user { var user = new PasswordArchive(); var users = new List <PasswordArchive>(); var bf = new BinaryFormatter(); var infile = new FileStream(FILE_NAME, FileMode.OpenOrCreate, FileAccess.Read); if (!File.Exists(FILE_NAME)) { return(null); } else { while (infile.Position < infile.Length) { users.Add((PasswordArchive)bf.Deserialize(infile)); } foreach (var u in users) { if (u.Username == userName) { user = u; break; } } if (System.String.IsNullOrEmpty(user.Username)) //so we can check for a null instance. { user = null; } } infile.Close(); return(user); }
public void Put(PasswordArchive passArchive) { passPersistence.Put(passArchive); }
public void Put(PasswordArchive passArchive) { saveLoad.Store(passArchive); }