Get encryption / decryption working for users.

This commit is contained in:
Tim Young 2017-08-09 16:52:54 -05:00
parent 1e598470ef
commit e6518e3918
2 changed files with 34 additions and 5 deletions

View File

@ -1743,7 +1743,24 @@ namespace EduNetworkBuilder
} }
else if (extension == ".enbu") else if (extension == ".enbu")
{ {
CurrentUser = new PersonClass(filename); int counter = 0;
PersonClass tUser = null;
while (counter < 3)
{
string tPass = NB.TextPromptBox("Enter a password", Properties.Resources.NBIco, true);
string tUserName = Path.GetFileNameWithoutExtension(filename);
string PasToUse = tUserName + tPass;
tUser = PersonClass.TryLoad(filename, PasToUse);
if (tUser != null) break;
counter++;
}
if(tUser == null)
{
//failed to load.
MessageBox.Show("Too many password failures. Exiting.");
return;
}
CurrentUser = tUser;
CurrentUser.filepath = Path.GetDirectoryName(filename); //store the directory CurrentUser.filepath = Path.GetDirectoryName(filename); //store the directory
OurSettings = NB.GetSettings(); //Grab the new settings from the user OurSettings = NB.GetSettings(); //Grab the new settings from the user
UpdateMenu(); UpdateMenu();

View File

@ -44,9 +44,8 @@ namespace EduNetworkBuilder
/// Used to determine if the user we are working with is the admin account. /// Used to determine if the user we are working with is the admin account.
/// </summary> /// </summary>
public bool isAdmin { get; protected set; } public bool isAdmin { get; protected set; }
/// <summary>
/// EverCompletedPuzzles is a list of puzzles that they have completed once. public string EncryptionPassword { get { return UserName + Password; } }
/// </summary>
public List<SchoolworkClass> Projects = new List<SchoolworkClass>(); public List<SchoolworkClass> Projects = new List<SchoolworkClass>();
@ -79,7 +78,20 @@ namespace EduNetworkBuilder
{ {
Load(reader); Load(reader);
} }
/// <summary>
/// Try to load the specified filename. Return a new person record if it succeeds.
/// Return null if it fails to load. (bad password, bad file, etc)
/// </summary>
/// <param name="Filename">The filename to load</param>
/// <param name="password">The password to try</param>
/// <returns></returns>
public static PersonClass TryLoad(string Filename, string password)
{
PersonClass pc = new PersonClass();
if (pc.Load(Filename, password))
return pc;
return null;
}
public void ChangePassword(string NewPassword) public void ChangePassword(string NewPassword)
{ {