private void RegisterUser(string userRegLog, string userRegPas) { using (EFDbContext db = new EFDbContext()) { foreach (var exuser in db.Users) { if (CypherClass.XORCipher(userRegLog, key) == exuser.UserName || CypherClass.XORCipher(userRegLog, key) == exuser.PassWord || CypherClass.XORCipher(userRegPas, key) == exuser.UserName || CypherClass.XORCipher(userRegPas, key) == exuser.PassWord) { localcheck = true; } } if (!localcheck) { if (db.Users.Count() == 0) { AddUser(new User() { UserName = CypherClass.XORCipher(userRegLog, key), PassWord = CypherClass.XORCipher(userRegPas, key), IsAdmin = true }, db); } else { AddUser(new User() { UserName = CypherClass.XORCipher(userRegLog, key), PassWord = CypherClass.XORCipher(userRegPas, key), IsAdmin = false }, db); } } } }
private void AdmDeleteBtn_Click(object sender, EventArgs e) { var selected_cell = AdminDataGrid.CurrentCell.FormattedValue; var selected_acc = accounts.SingleOrDefault(x => x.UserName == selected_cell.ToString() || x.Password == selected_cell.ToString()); foreach (DataGridViewCell dgvc in AdminDataGrid.SelectedCells) { if (dgvc.Selected == true) { AdminDataGrid.Rows.RemoveAt(dgvc.RowIndex); accounts.Remove(selected_acc); } } using (EFDbContext db = new EFDbContext()) { foreach (var item in db.Users) { if (item.UserName == CypherClass.XORCipher(selected_acc.UserName, key) || item.PassWord == CypherClass.XORCipher(selected_acc.Password, key)) { var queryDeleteLinks = from links in db.Shortcuts where links.UserId == item.Id select links; db.Shortcuts.RemoveRange(queryDeleteLinks); db.Users.Remove(item); } } db.SaveChanges(); } }
private void ExitLabel_Click(object sender, EventArgs e) { selected_link.Description = CypherClass.XORCipher(selected_link.Description, key); selected_link.URL = CypherClass.XORCipher(selected_link.URL, key); CloseForm(); }
private void DeleteBtn_Click(object sender, EventArgs e) { var selected = shortcutsDataGrid.CurrentCell.FormattedValue; var selected_link = links.SingleOrDefault(x => x.URL == selected.ToString() || x.Description == selected.ToString()); foreach (DataGridViewCell dgvc in shortcutsDataGrid.SelectedCells) { if (dgvc.Selected == true) { shortcutsDataGrid.Rows.RemoveAt(dgvc.RowIndex); links.Remove(selected_link); } } using (db = new EFDbContext()) { foreach (var item in db.Shortcuts) { if (item.Link == CypherClass.XORCipher(selected_link.URL, key) || item.Desc == CypherClass.XORCipher(selected_link.Description, key)) { db.Shortcuts.Remove(item); } } db.SaveChanges(); } }
private void EditSelectedLinkForm_Load(object sender, EventArgs e) { UrlTextBox.Text = selected_link.URL; DescTextBox.Text = selected_link.Description; selected_link.URL = CypherClass.XORCipher(selected_link.URL, key); selected_link.Description = CypherClass.XORCipher(selected_link.Description, key); using (EFDbContext db = new EFDbContext()) selected_db = db.Shortcuts.SingleOrDefault(cut => cut.Link == selected_link.URL && cut.UserId == id); }
private void LoginMethod(string userLogin, string userPass, ref bool successfulLog) { if (loginBox.Text == "" || passBox.Text == "") { MessageBox.Show("Ви не заповнили поля для авторизації"); } using (EFDbContext db = new EFDbContext()) { foreach (var user in db.Users) { if (user.UserName.Equals(CypherClass.XORCipher(userLogin, key)) && user.PassWord.Equals(CypherClass.XORCipher(userPass, key))) { SuccessfulLogin(user, ref successfulLog); break; } } } }
private void AdminForm_Load(object sender, EventArgs e) { using (EFDbContext db = new EFDbContext()) { foreach (var item in db.Users) { if (item.Id != id) { item.PassWord = CypherClass.XORCipher(item.PassWord, key); item.UserName = CypherClass.XORCipher(item.UserName, key); accounts.Add(new VisibleAccounts() { UserName = item.UserName, Password = item.PassWord }); } } } AdminDataGrid.DataSource = accounts; }
private void SaveBtn_Click(object sender, EventArgs e) { string link = linkbox.Text; string description = descbox.Text; using (EFDbContext db = new EFDbContext()) { db.Shortcuts.Add(new Entities.Shortcut() { Link = CypherClass.XORCipher(link, key), Desc = CypherClass.XORCipher(description, key), UserId = user.Id }); db.SaveChanges(); } cutsform.Enabled = true; cutsform.Dispose(); this.Hide(); CutsForm cutsf = new CutsForm(user); cutsf.Show(); }
private void EditSaveChangesBtn_Click(object sender, EventArgs e) { string url = UrlTextBox.Text, desc = DescTextBox.Text; selected_link.URL = url; selected_link.Description = desc; using (EFDbContext db = new EFDbContext()) { var new_item = db.Shortcuts.SingleOrDefault(cut => cut.Link == selected_db.Link); new_item.Link = selected_link.URL; new_item.Desc = selected_link.Description; new_item.Link = CypherClass.XORCipher(new_item.Link, key); new_item.Desc = CypherClass.XORCipher(new_item.Desc, key); db.Entry(new_item).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } CloseForm(); }
private void CutsForm_Load(object sender, EventArgs e) { if (user.IsAdmin == true) { AdmBtn.Visible = true; } using (db = new EFDbContext()) { foreach (var item in db.Shortcuts) { if (item.UserId == user.Id) { links.Add(new VisibleLinks() { URL = CypherClass.XORCipher(item.Link, key), Description = CypherClass.XORCipher(item.Desc, key) }); } } shortcutsDataGrid.DataSource = links; } }