public SignInAccount GetMostRecentlyUsedAccount() { SignInAccount account = GetAccountsBySignInDate().FirstOrDefault(); if (Count > 1) { var otherAccounts = storedAccounts.Where(a => a.Value != account).ToArray(); foreach (var otherAccount in otherAccounts) { storedAccounts.Remove(otherAccount.Key); } } return(account); }
public void LoadAccounts() { storedAccounts.Clear(); string[] fileNames = Directory.GetFiles(Paths.DataDirectory, "*.account"); foreach (string fileName in fileNames) { try { SettingsFile sf = new SettingsFile(); sf.Load(fileName); SignInAccount newAccount = new SignInAccount { SignInUsername = sf.GetString("SignInUsername", ""), PlayerName = sf.GetString("PlayerName", ""), Password = sf.GetString("Password", ""), LastUrl = sf.GetString("LastUrl", "") }; if (newAccount.Password.Length > 0) { newAccount.Password = PasswordSecurity.DecryptPassword(newAccount.Password); } string tickString = sf.GetString("SignInDate", "0"); long ticks; if (Int64.TryParse(tickString, out ticks) && ticks > DateTime.MinValue.Ticks && ticks <= DateTime.MaxValue.Ticks) { newAccount.SignInDate = new DateTime(ticks); } else { newAccount.SignInDate = DateTime.MinValue; } AddAccount(newAccount); } catch (Exception ex) { MainForm.Log("AccountManager.LoadAccounts: " + ex); } } SaveAllAccounts(); }
void SaveAccounts() { if( activeAccount == null ) { // If currenty-entered account information is not on record, add it to AccountManager activeAccount = new SignInAccount { SignInUsername = cSignInUsername.Text, Password = tSignInPassword.Text, PlayerName = signInSession.MinecraftUsername, LastUrl = tSignInUrl.Text }; accounts.AddAccount( activeAccount ); } activeAccount.SignInDate = DateTime.UtcNow; if( !xMultiUser.Checked ) { // If no multi-user, clear all accounts except active one accounts.RemoveAllAccounts(); accounts.AddAccount( activeAccount ); } accounts.SaveAllAccounts(); }
// Load account info from the old password file (saved-login.dat). Delete it after done. void LoadLegacyPasswordSaveFile() { if( xRememberUsername.Checked ) { string[] loginData = File.ReadAllLines( Paths.LegacyPasswordSaveFile ); SignInAccount oldAccount = new SignInAccount { SignInUsername = loginData[0] }; oldAccount.PlayerName = ( loginData.Length > 2 ? loginData[2] : oldAccount.SignInUsername ); if( xRememberPassword.Checked ) { oldAccount.Password = loginData[1]; } else { oldAccount.Password = ""; } if( xRememberServer.Checked ) { oldAccount.LastUrl = ( loginData.Length > 3 ? loginData[3] : "" ); } else { oldAccount.LastUrl = ""; } oldAccount.SignInDate = DateTime.UtcNow; if( !accounts.HasAccount( oldAccount.SignInUsername ) ) { accounts.AddAccount( oldAccount ); } accounts.SaveAllAccounts(); } File.Delete( Paths.LegacyPasswordSaveFile ); }
void cSignInUsername_TextChanged( object sender, EventArgs e ) { SignInFieldChanged( sender, e ); string givenUsername = cSignInUsername.Text; SignInAccount acct = accounts.FindAccount( givenUsername ); if( acct != null ) { // Recognized account! Load info from it. SelectActiveAccount( acct ); } else { // Unrecognized account if( activeAccount != null ) { // Reset password when going from known to unknown account tSignInPassword.Text = ""; } activeAccount = null; bForgetActiveAccount.Enabled = false; bForgetActiveAccount.Text = "Forget account: (no account selected)"; } }
// Set given account as the active one. void SelectActiveAccount( SignInAccount account ) { activeAccount = account; if( account == null ) { bForgetActiveAccount.Enabled = false; bForgetActiveAccount.Text = "Forget account: (no account selected)"; } else { bForgetActiveAccount.Enabled = true; bForgetActiveAccount.Text = "Forget account: " + activeAccount.SignInUsername; cSignInUsername.Text = account.SignInUsername; if( xRememberPassword.Checked ) { tSignInPassword.Text = account.Password; } else { tSignInPassword.Text = ""; } if( xRememberServer.Checked && account.LastUrl.Length > 0 ) { tSignInUrl.Text = account.LastUrl; } } }
public void RemoveAccount(SignInAccount account) { storedAccounts.Remove(account.SignInUsername.ToLower()); RemoveAllAccountFiles(); SaveAllAccounts(); }
public void AddAccount(SignInAccount newAccount) { storedAccounts.Add(newAccount.SignInUsername.ToLowerInvariant(), newAccount); }
public void LoadAccounts() { storedAccounts.Clear(); string[] fileNames = Directory.GetFiles( Paths.DataDirectory, "*.account" ); foreach( string fileName in fileNames ) { try { SettingsFile sf = new SettingsFile(); sf.Load( fileName ); SignInAccount newAccount = new SignInAccount { SignInUsername = sf.GetString( "SignInUsername", "" ), PlayerName = sf.GetString( "PlayerName", "" ), Password = sf.GetString( "Password", "" ), LastUrl = sf.GetString( "LastUrl", "" ) }; if( newAccount.Password.Length > 0 ) { newAccount.Password = PasswordSecurity.DecryptPassword( newAccount.Password ); } string tickString = sf.GetString( "SignInDate", "0" ); long ticks; if( Int64.TryParse( tickString, out ticks ) && ticks > DateTime.MinValue.Ticks && ticks <= DateTime.MaxValue.Ticks ) { newAccount.SignInDate = new DateTime( ticks ); } else { newAccount.SignInDate = DateTime.MinValue; } AddAccount( newAccount ); } catch( Exception ex ) { MainForm.Log( "AccountManager.LoadAccounts: " + ex ); } } SaveAllAccounts(); }
public void AddAccount( SignInAccount newAccount ) { storedAccounts.Add( newAccount.SignInUsername.ToLowerInvariant(), newAccount ); }
public void RemoveAccount( SignInAccount account ) { storedAccounts.Remove( account.SignInUsername.ToLower() ); RemoveAllAccountFiles(); SaveAllAccounts(); }