/// <summary> /// Removes a selected combobox item from memory and overwrites the file with the new data. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void btnDelete_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(cbWebsites.Text)) { var descriptionName = cbWebsites.Text; UserSessionData.UserInformationCollection.Remove(UserSessionData.UserInformationCollection.Where(x => x.Description == cbWebsites.Text).FirstOrDefault()); UserSessionData.SaveData(); UserSessionData.LoadData(); BindDescriptionMenu(); notification = new DialogBox(descriptionName + " has been successfully removed!", MetroFramework.MetroColorStyle.Green, this.DesktopLocation, "Information Removed"); notification.Show(); } else { notification = new DialogBox("There must be a website selected to remove data information for.", MetroFramework.MetroColorStyle.Red, this.DesktopLocation, "No Website Selected"); notification.Show(); } if (!UserSessionData.UserInformationCollection.Any()) { if (notification != null) { notification.Close(); } PasswordManagement.SelectTab(InfoAddTab); notification = new DialogBox("All websites have been removed. Add new ones if you would like!", this.Style, this.DesktopLocation); notification.Show(); } }
public async Task SeedAllAsync(CancellationToken cancellation) { #region SeedData var adminRole = new Role { Name = "Admin", Description = "System Admin Role", IsVital = true, }; if (!_roleRepository.GetAll().Any()) { await _roleRepository.AddAsync(adminRole); await _roleRepository.AddAsync(new Role { Name = "Manager", Description = "Mange User", IsVital = true, }); await _roleRepository.AddAsync(new Role { Name = "User", Description = "System Admin Role", IsVital = true, }); } if (!_userRepository.GetAll().Any()) { await _userRepository.AddAsync(new User { FirstName = "نیما", LastName = "نصرتی", Email = "*****@*****.**", Password = PasswordManagement.HashPass("nima1234!"), ActiveCode = Guid.NewGuid().ToString("N"), Mobile = "09107602786", IsEmailConfirm = true, IsMobileConfirm = true, RegisterDate = DateTime.Now, ModifiedDate = DateTime.Now.AddDays(2), Roles = new List <Role> { adminRole } }); } #endregion }
/// <summary> /// Initializes a new instance of the <see cref="PRIM_Software"/> class. /// Sets all first-session-time use/one time settings. /// </summary> public PRIM_Software() { InitializeComponent(); SetDefaultText(); btnReset.BackColor = Color.DimGray; btnReset.Enabled = false; cbHidePasswordDisplay.Checked = true; cbHideNewPasswords.Checked = true; PasswordManagement.DisableTab(InfoManagementTab); PasswordManagement.DisableTab(InfoAddTab); InitialDisplayModeSelected = false; cbRedirect.Checked = true; }
private static string GetApplicationModeString() { if (PasswordManagement.GetApplicationMode() == ApplicationMode.ReadMode) { return("Read Mode"); } if (PasswordManagement.GetApplicationMode() == ApplicationMode.ModifyMode) { return("Modify Mode"); } return(""); }
/// <summary> /// Updates the user information collection in memory and writes to it's respective file /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void btnAddNew_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(tbWebDescription.Text) && !string.IsNullOrEmpty(tbNewPassword.Text) && !string.IsNullOrEmpty(tbConfirmNewPassword.Text)) { var descriptionName = tbWebDescription.Text; var siteList = UserSessionData.UserInformationCollection.Select(x => x.Description); if (!siteList.Contains(tbWebDescription.Text)) { if (tbNewPassword.Text.Equals(tbConfirmNewPassword.Text)) { UserData.UserInformation newInfo = new UserData.UserInformation(); newInfo.Description = tbWebDescription.Text; newInfo.Password = tbConfirmNewPassword.Text; UserSessionData.UserInformationCollection.Add(newInfo); UserSessionData.LoadOrCreateEncryptionKey(); UserSessionData.SaveData(); UserSessionData.LoadData(); BindDescriptionMenu(); if (cbRedirect.Checked) { PasswordManagement.SelectTab(InfoManagementTab); } else { ClearApplicationData(); } notification = new DialogBox("Information for: " + descriptionName + " has been successfully added!", MetroFramework.MetroColorStyle.Green, this.DesktopLocation, "Information Saved"); notification.Show(); } else { notification = new DialogBox("Your passwords must patch.", MetroFramework.MetroColorStyle.Red, this.DesktopLocation, "Error"); notification.Show(); } } else { notification = new DialogBox(descriptionName + " already exists.", MetroFramework.MetroColorStyle.Red, this.DesktopLocation, "Error"); notification.Show(); } } else { notification = new DialogBox("A Description, Password and Confirmation Password are needed.", MetroFramework.MetroColorStyle.Red, this.DesktopLocation, "Error"); notification.Show(); } }
/// <summary> /// Resets the application and data to first time use. All passwords and keys are deleted. /// Files are recreated on selection screen. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void btnReset_Click(object sender, EventArgs e) { File.Delete(AppDomain.CurrentDomain.BaseDirectory + Constants.FilePaths.WorkInformation); File.Delete(AppDomain.CurrentDomain.BaseDirectory + Constants.FilePaths.PersonalInformation); File.Delete(AppDomain.CurrentDomain.BaseDirectory + Constants.FilePaths.SharedInformation); File.Delete(AppDomain.CurrentDomain.BaseDirectory + Constants.FilePaths.SocialMediaInformation); File.Delete(AppDomain.CurrentDomain.BaseDirectory + Constants.FilePaths.OtherInformation); File.Delete(AppDomain.CurrentDomain.BaseDirectory + Constants.FilePaths.Key); File.Delete(AppDomain.CurrentDomain.BaseDirectory + Constants.FilePaths.InitializationVector); ClearApplicationData(); InitialDisplayModeSelected = false; PasswordManagement.DisableTab(InfoManagementTab); PasswordManagement.DisableTab(InfoAddTab); PasswordManagement.SelectTab(InfoTypeSelectionTab); notification = new DialogBox("All data has been Reset! A new key has been generated. Please do not modify it.", MetroFramework.MetroColorStyle.Silver, this.DesktopLocation, "Reset"); notification.Show(); }
public void Update(User userParam, string password = null) { var user = _context.Users.Find(userParam.Id); if (user == null) { throw new AppException("User not found"); } // update username if it has changed if (!string.IsNullOrWhiteSpace(userParam.Username) && userParam.Username != user.Username) { // throw error if the new username is already taken if (_context.Users.Any(x => x.Username == userParam.Username)) { throw new AppException("Username " + userParam.Username + " is already taken"); } user.Username = userParam.Username; } // update user properties if provided if (!string.IsNullOrWhiteSpace(userParam.FirstName)) { user.FirstName = userParam.FirstName; } if (!string.IsNullOrWhiteSpace(userParam.LastName)) { user.LastName = userParam.LastName; } // update password if provided if (!string.IsNullOrWhiteSpace(password)) { PasswordManagement.CreatePasswordHash(password, out byte[] passwordHash, out byte[] passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; } _context.Users.Update(user); _context.SaveChanges(); }
public async Task <Result <TokenDto> > Handle(Command.LoginCommand.LoginCommand request, CancellationToken cancellationToken) { var user = await _userRepository.GetAsync(x => x.Mobile == request.Mobile && x.IsDelete == false, cancellationToken); if (user is null) { return(Result <TokenDto> .Failed(new BadRequestObjectResult(new ApiMessage(ResponseMessage.InvalidUserNameOrPassword)))); } if (PasswordManagement.CheckPassword(request.Password, user.Password) == false) { return(Result <TokenDto> .Failed(new BadRequestObjectResult(new ApiMessage(ResponseMessage.InvalidUserNameOrPassword)))); } if (user.IsMobileConfirm == false) { return(Result <TokenDto> .Failed(new BadRequestObjectResult(new ApiMessage(ResponseMessage.AccountDeactivate)))); } var userToken = await _userTokenRepository.GetAsync(x => x.IsExpired == false && x.ExpiredDate >= DateTime.Now && x.UserId == user.Id, cancellationToken); //if user already have valid token in database if (userToken != null) { return(Result <TokenDto> .SuccessFul(new TokenDto { AccessToken = userToken.Token, RoleName = user.Roles.FirstOrDefault()?.Name })); } var result = await _tokenGenerator.Generate(user, cancellationToken); return(Result <TokenDto> .SuccessFul(new TokenDto { AccessToken = result.Data.AccessToken, RoleName = result.Data.RoleName })); }
public CreateResponse Create(RegisterModel registerModel) { CreateResponse response = new CreateResponse(); // validation if (string.IsNullOrWhiteSpace(registerModel.Password)) { response.Error = new Error(1, "Password was not supplied."); return(response); } if (_context.Users.Any(x => x.Username == registerModel.Username)) { response.Error = new Error(2, "That username is taken."); return(response); } if (registerModel.Password != registerModel.ConfirmPassword) { response.Error = new Error(3, "Password and ConfirmPassword did not match."); return(response); } response.User = new User(); response.User.FirstName = registerModel.FirstName; response.User.LastName = registerModel.LastName; response.User.Username = registerModel.Username; PasswordManagement.CreatePasswordHash(registerModel.Password, out byte[] passwordHash, out byte[] passwordSalt); response.User.PasswordHash = passwordHash; response.User.PasswordSalt = passwordSalt; _context.Users.Add(response.User); _context.SaveChanges(); return(response); }
public User Authenticate(string username, string password) { if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { return(null); } var user = _context.Users.SingleOrDefault(x => x.Username == username); // check if username exists if (user == null) { return(null); } // check if password is correct if (!PasswordManagement.VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt)) { return(null); } // authentication successful return(user); }
public ActionResult SetupUsers() { HttpPostedFileBase fileUpload = Request.Files[0]; var users = new List <EdayRoomUser>(); if (fileUpload != null) { fileUpload.SaveAs(Server.MapPath("~/temp/" + fileUpload.FileName)); var fi = new FileInfo(Server.MapPath("~/temp/" + fileUpload.FileName)); var fiOut = new FileInfo( Path.Combine( Server.MapPath(ConfigurationManager.AppSettings["userFilesDirectory"]), string.Format("{0}_" + fileUpload.FileName, DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss")))); var db = new edayRoomEntities(); List <string> existingUsers = (from u in db.users select u.username).ToList(); var package = new ExcelPackage(fi); ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; worksheet.Cells[1, 3].Value = "usuario"; worksheet.Cells[1, 4].Value = "password"; for (int i = 2; i <= worksheet.Dimension.End.Row; i++) { var nombre = (string)worksheet.Cells[i, 1].Value; var apellido = (string)worksheet.Cells[i, 2].Value; var u = new EdayRoomUser { Name = nombre + " " + apellido, Password = PasswordManagement.GenerateRandomPassword(6), }; u.Username = u.Name.Replace(" ", ".").ToLower(); int uid = 1; if (existingUsers.Any(us => us == u.Username)) { string original = u.Username; while (true) { u.Username = original + "." + uid; if (existingUsers.All(us => us != u.Username)) { break; } uid++; } } existingUsers.Add(u.Username); worksheet.Cells[i, 3].Value = u.Username; worksheet.Cells[i, 4].Value = u.Password; users.Add(u); string salt = ""; string passwordHash = PasswordManagement.GeneratePasswordHash(u.Password, out salt); db.users.AddObject(new user { nombre = nombre, apellido = apellido, username = u.Username, salt = salt, hash = passwordHash }); } db.UserFiles.AddObject(new UserFile { fileName = fiOut.Name }); db.SaveChanges(); package.SaveAs(fiOut); } var errores = new List <string> { "error " + fileUpload.FileName }; return(GetAllUsers(errores, users)); }
public string LoadUsuarios() { HttpPostedFileBase fileUpload = Request.Files[0]; var users = new List <EdayRoomUser>(); if (fileUpload != null) { fileUpload.SaveAs(Server.MapPath("~/temp/" + fileUpload.FileName)); var fi = new FileInfo(Server.MapPath("~/temp/" + fileUpload.FileName)); var fiOut = new FileInfo( Path.Combine( Server.MapPath(ConfigurationManager.AppSettings["userFilesDirectory"]), string.Format("{0}_" + fileUpload.FileName, DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss")))); var db = new edayRoomEntities(); List <string> existingUsers = (from u in db.users select u.username).ToList(); var package = new ExcelPackage(fi); var passwordPackage = new ExcelPackage(); ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; passwordPackage.Workbook.Worksheets.Add("Passwords"); ExcelWorksheet passwordWorksheet = passwordPackage.Workbook.Worksheets["Passwords"]; passwordWorksheet.Cells[1, 1].Value = "Nombre"; passwordWorksheet.Cells[1, 3].Value = "Apellido"; passwordWorksheet.Cells[1, 3].Value = "usuario"; passwordWorksheet.Cells[1, 4].Value = "password"; for (int i = 2; i <= worksheet.Dimension.End.Row; i++) { var nombre = (string)worksheet.Cells[i, 1].Value; string apellido = worksheet.Cells[i, 2].Value == null ? "" : worksheet.Cells[i, 2].Value.ToString(); string grupo = (string)worksheet.Cells[i, 3].Value ?? ""; bool admin = ((string)worksheet.Cells[i, 4].Value).ToLower() == "si"; bool supervisor = ((string)worksheet.Cells[i, 5].Value).ToLower() == "si"; bool leader = ((string)worksheet.Cells[i, 6].Value).ToLower() == "si"; bool participacion = ((string)worksheet.Cells[i, 7].Value).ToLower() == "si"; bool movilizacion = ((string)worksheet.Cells[i, 8].Value).ToLower() == "si"; bool exitpolls = ((string)worksheet.Cells[i, 9].Value).ToLower() == "si"; bool quickcount = ((string)worksheet.Cells[i, 10].Value).ToLower() == "si"; bool totalizacion = ((string)worksheet.Cells[i, 11].Value).ToLower() == "si"; bool dashboard = ((string)worksheet.Cells[i, 12].Value).ToLower() == "si"; bool alertas = ((string)worksheet.Cells[i, 13].Value).ToLower() == "si"; var password = (worksheet.Cells[i, 14].Value == null ? "" : worksheet.Cells[i, 14].Value.ToString()); var u = new EdayRoomUser { Name = nombre + " " + apellido, Password = string.IsNullOrWhiteSpace(password) ? PasswordManagement.GenerateRandomPassword(6) : password, Group = grupo, Admin = admin, Leader = leader, Participacion = participacion, Movilizacion = movilizacion, ExitPolls = exitpolls, QuickCount = quickcount, Totalizacion = totalizacion, Dashboard = dashboard }; u.Username = nombre.Trim().Split(' ').First().ToLower() + "." + apellido.Trim().Split(' ').First().ToLower(); byte[] b = Encoding.GetEncoding(1251).GetBytes(u.Username); u.Username = Encoding.ASCII.GetString(b); int uid = 1; if (existingUsers.Any(us => us == u.Username)) { string original = u.Username; while (true) { u.Username = original + "." + uid; if (existingUsers.All(us => us != u.Username)) { break; } uid++; } } existingUsers.Add(u.Username); worksheet.Cells[i, 3].Value = u.Username; worksheet.Cells[i, 4].Value = u.Password; users.Add(u); string salt = ""; string passwordHash = u.Password;//PasswordManagement.GeneratePasswordHash(u.Password, out salt); db.users.AddObject(new user { nombre = nombre, apellido = apellido, username = u.Username, salt = salt, hash = passwordHash, grupo = grupo, admin = admin, leader = leader, participacion = participacion, movilizacion = movilizacion, exitpolls = exitpolls, quickcount = quickcount, totalizacion = totalizacion, dashboard = dashboard, supervisor = supervisor, alertas = alertas }); } db.UserFiles.AddObject(new UserFile { fileName = fiOut.Name }); db.SaveChanges(); package.SaveAs(fiOut); var errores = new List <string> { "error " + fileUpload.FileName }; } return("YEAH"); }
static void Main(string[] args) { var isAlive = true; var loginWasSuccessful = false; while (isAlive) { Console.WriteLine("===| Menu |==="); Console.WriteLine("===| 1) Create account. |==="); Console.WriteLine("===| 2) Login. |==="); Console.WriteLine("===| q) Quit. |==="); var data = Console.ReadLine(); if (data == "q") { isAlive = false; } else if (data == "1") //Register { Console.WriteLine("Pick one of algo to store your master password:"******"===| 1) HMAC |==="); Console.WriteLine("===| 2) SHA512 |==="); var algorithm = Console.ReadLine(); CryptoEnum cryptoEnum = CryptoEnum.None; switch (algorithm) { case "1": cryptoEnum = CryptoEnum.HMAC; break; case "2": cryptoEnum = CryptoEnum.SHA512; break; } Configuration.Configure(cryptoEnum); //data for register Console.WriteLine("Enter login:"******"Enter password:"******"2") //Login { Console.WriteLine("Enter login:"******"Enter password:"******"Login was successful."); } else { Console.WriteLine("Your data was wrong."); if (loginResult.TimeoutDurationInSeconds > 0) { Console.WriteLine($"Please wait {loginResult.TimeoutDurationInSeconds} second since try login once again."); } else if (loginResult.TimeoutDurationInSeconds == -1) { Console.WriteLine("Your address IP are permanently banned."); } } //Console.WriteLine(loginWasSuccessful ? "Login was successful." : "User data was wrong."); } if (loginWasSuccessful) { while (true) { Console.WriteLine("===| 1) Manage passwords. |==="); Console.WriteLine("===| 2) Store new password. |==="); Console.WriteLine("===| 3) Change master password. |==="); Console.WriteLine("===| 4) Show user login data. |==="); Console.WriteLine("===| 5) Show ip addresses data. |==="); Console.WriteLine("===| q) Quit. |==="); var x = Console.ReadLine(); if (x == "q") { Console.WriteLine("Shutdown.. Thanks for using app."); Environment.Exit(0); } else if (x == "1") //Show one password => Manage passwords { Console.WriteLine($"===| You are in {GetApplicationModeString()} type 0) to change mode. |==="); Console.WriteLine($"===| ============================================ |==="); Console.WriteLine("===| 1) Show specific password. |==="); Console.WriteLine("===| 2) Show passwords. |==="); //todo remove Console.WriteLine("===| 3) Share specific password. |==="); Console.WriteLine("===| 4) Show pending passwords. |==="); Console.WriteLine("===| 5) Manage your password data. |==="); //List all, allow change only personal passwords var y = Console.ReadLine(); if (y == "0") { PasswordManagement.SwitchApplicationMode(); } else if (y == "1") { var passwordsData = PasswordManagement.GetPasswordsList().ToList(); if (!passwordsData.Any()) { Console.WriteLine("There is no password stored for this user."); continue; } foreach (var password in passwordsData) { Console.WriteLine($"Id: {password.Id} | Web Address: { password.WebAddress } | Login: { password.Login } | Description: { password.Description }"); } Console.WriteLine("Type id password which you want release:"); var id = Console.ReadLine(); var decryptedPassword = PasswordManagement.GetDecryptedPasswordData(int.Parse(id)); Console.WriteLine($"Web Address: { decryptedPassword.WebAddress } | Login: { decryptedPassword.Login } | Password: { decryptedPassword.Password } | Description: { decryptedPassword.Description }"); } else if (y == "2") { ShowPasswordsData(PasswordManagement.GetDecryptedPasswordsData().ToList()); } else if (y == "3") { ShowPasswordsData(PasswordManagement.GetPasswordsDataToShare().ToList()); //Only available to share Console.WriteLine("Type id password which you want share:"); var idPassword = Console.ReadLine(); //show all users var userInfos = AccountManagement.GetAllOtherUserInfo().ToList(); foreach (var userInfo in userInfos) { Console.WriteLine($"Id: {userInfo.Id} | Username: {userInfo.Username}"); } Console.WriteLine("Type id user which you want share chosen password:"******"4") { var passwordSharesInfo = PasswordManagement.GetPendingPasswordForCurrentUser().ToList(); if (!passwordSharesInfo.Any()) { Console.WriteLine("There is no pending password for this user."); continue; } foreach (var pendingPasswordShare in passwordSharesInfo) { Console.WriteLine($"Id: {pendingPasswordShare.Id} | WebsiteAddress: {pendingPasswordShare.WebsiteAddress} | Description: {pendingPasswordShare.Description} " + $"SourceUsername: {pendingPasswordShare.SourceUsername}"); } Console.WriteLine("Type id password which you want to accept:"); var shareId = Console.ReadLine(); PasswordManagement.AcceptPasswordShare(int.Parse(shareId)); } else if (y == "5") { Console.WriteLine("Trying enter password modifying platform.."); if (PasswordManagement.GetApplicationMode() == ApplicationMode.ReadMode) { Console.WriteLine("To enter this functionalities you need switch to modify mode in aplication."); continue; } ShowPasswordsData(PasswordManagement.GetDecryptedPasswordsData().ToList()); Console.WriteLine("Type id password which you want manage:"); var idPassword = Console.ReadLine(); if (PasswordManagement.CheckEditPasswordPossibility(int.Parse(idPassword)) == EditPasswordPossibility.Ok) { Console.WriteLine("What you want to do?"); Console.WriteLine("1) Edit password data."); Console.WriteLine("2) Remove password."); var editType = Console.ReadLine(); if (editType == "1") { Console.WriteLine("Fill all new data, if you don't want to change something, leave field empty."); Console.WriteLine("Login"); var newLogin = Console.ReadLine(); Console.WriteLine("Password"); var newPassword = Console.ReadLine(); Console.WriteLine("Web Address"); var newWebAddress = Console.ReadLine(); Console.WriteLine("Description"); var newDescription = Console.ReadLine(); PasswordManagement.EditPassword(new EditPasswordData { PasswordId = int.Parse(idPassword), NewLogin = newLogin, NewPassword = newPassword, NewWebAddress = newWebAddress, NewDescription = newDescription }); } else if (editType == "2") { PasswordManagement.RemovePassword(int.Parse(idPassword)); } } else { Console.WriteLine("No access to modify this password."); } } else { Console.WriteLine("Wrong choise."); } } else if (x == "2") //Store password { Console.WriteLine("Enter web address:"); var webAddress = Console.ReadLine(); Console.WriteLine("Enter login for this website:"); var loginForWebsite = Console.ReadLine(); Console.WriteLine("Enter password for this website:"); var passwordForWebsite = Console.ReadLine(); Console.WriteLine("Enter description (optional)"); var description = Console.ReadLine(); if (string.IsNullOrEmpty(description)) // TODO XD?? XD { description = null; } PasswordManagement.StorePassword(new PasswordData { WebAddress = webAddress, Login = loginForWebsite, Password = passwordForWebsite, Description = description }); } else if (x == "3") //Change Password { Console.WriteLine("Enter old password:"******"Enter new password:"******"Re enter new password:"******"Password doesn't match."); } } else if (x == "4") { var allLoginAttemptsDataForUser = AccountManagement.GetLoginAttemptsView(); Console.WriteLine("Login Attempt Date | Was Succesfull?"); foreach (var attemptsData in allLoginAttemptsDataForUser) { Console.WriteLine($"{ attemptsData.LoginAttemptDate } | { attemptsData.WasSuccess }"); } } else if (x == "5") { var bannedIpAddresses = AccountManagement.GetPermanentlyBannedIpAddresses(); Console.WriteLine("Ip Address | Is Banned Pernamently?"); if (bannedIpAddresses.Any()) { foreach (var bannedIpAddress in bannedIpAddresses) { Console.WriteLine($"{ bannedIpAddress } | true"); } } else { Console.WriteLine($"No address found."); } Console.WriteLine("Enter ip address which you want unlock or type 0) to skip this process."); var z = Console.ReadLine(); if (z == "0") { continue; } if (bannedIpAddresses.Contains(z)) { AccountManagement.UnbanIpAddress(z); Console.WriteLine("Address was unbanned."); } } } } } }
/// <summary> /// Loads /creates encryption keys and file data based on what was selected /// on the selection screen /// </summary> /// <param name="sender">The selected metro tile.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void SetDisplayMode(object sender, EventArgs e) { if (!InitialDisplayModeSelected) { PasswordManagement.EnableTab(InfoManagementTab); PasswordManagement.EnableTab(InfoAddTab); } if (notification != null) { notification.Close(); } ClearApplicationData(); cbWebsites.DataSource = null; var tile = (MetroFramework.Controls.MetroTile)sender; switch (tile.Name) { case "mtWork": this.Text = Constants.InformationSelectionScreen.WorkManagement; this.Style = MetroFramework.MetroColorStyle.Default; Display = new DisplayMode(AppDomain.CurrentDomain.BaseDirectory + Constants.FilePaths.WorkInformation); break; case "mtPersonal": this.Text = Constants.InformationSelectionScreen.PersonalManagement; this.Style = MetroFramework.MetroColorStyle.Yellow; Display = new DisplayMode(AppDomain.CurrentDomain.BaseDirectory + Constants.FilePaths.PersonalInformation); break; case "mtSocialMedia": this.Text = Constants.InformationSelectionScreen.SocialMediaManagement; this.Style = MetroFramework.MetroColorStyle.Purple; Display = new DisplayMode(AppDomain.CurrentDomain.BaseDirectory + Constants.FilePaths.SocialMediaInformation); break; case "mtSharedContent": this.Text = Constants.InformationSelectionScreen.SharedContentManagement; this.Style = MetroFramework.MetroColorStyle.Green; Display = new DisplayMode(AppDomain.CurrentDomain.BaseDirectory + Constants.FilePaths.SharedInformation); break; case "mtOther": this.Text = Constants.InformationSelectionScreen.OtherManagement; this.Style = MetroFramework.MetroColorStyle.Orange; Display = new DisplayMode(AppDomain.CurrentDomain.BaseDirectory + Constants.FilePaths.OtherInformation); break; default: break; } this.Refresh(); UserSessionData = new UserData(Display); if (UserSessionData.LoadOrCreateEncryptionKey()) { if (UserSessionData.LoadData()) { PasswordManagement.SelectTab(InfoManagementTab); BindDescriptionMenu(); } else { PasswordManagement.SelectTab(InfoAddTab); notification = new DialogBox(Constants.InformationSelectionScreen.NoData, this.Style, this.DesktopLocation); notification.Show(); } } else { PasswordManagement.SelectTab(InfoAddTab); notification = new DialogBox(Constants.InformationSelectionScreen.FirstTimeUseMessage, this.Style, this.DesktopLocation); notification.Show(); } }
/// <summary> /// Resets the app settings to default and redirects the user from the Add tab /// to the selection tab. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void btnCancel_Click(object sender, EventArgs e) { ClearApplicationData(); PasswordManagement.SelectTab(InfoTypeSelectionTab); }