private void Save() { try { if (string.IsNullOrEmpty(Password) || string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Name)) { throw new Exception("All fields are required."); } PasswordItem pwd = new PasswordItem(); pwd.Username = Username; pwd.Password = Password; pwd.Name = Name; if (isEdit) { pwd.ID = existing.ID; ds.UpdatePassword(pwd); } else { ds.AddPassword(pwd); } Cancelled = false; window.Close(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
public static async Task UploadPasswords(string token, string userSalt, string secretKey, List <Password> passwords) { var pwdItems = new List <PasswordItem>(); foreach (var password in passwords) { var pwdItem = new PasswordItem { Name = password.Name, Url = password.Url, Login = password.Login, Description = password.Description, Password = password.SecurePassword.GetAsString() }; pwdItems.Add(pwdItem); } var encoded = EncodePasswords(userSalt, secretKey, pwdItems); var client = GetHttpClient(); client.DefaultRequestHeaders.Remove("token"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Add("token", token); var request = new HttpRequestMessage(HttpMethod.Post, "api/pwdman/file"); var json = JsonSerializer.Serialize(ConvertToHexString(encoded)); request.Content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.SendAsync(request); await EnsureSuccess(response); }
private void button_Click_CopyLogin(object sender, RoutedEventArgs e) { PasswordItem itemButton = GetPasswordItem(sender); Clipboard.SetText(itemButton.login); textBlock.Text = $"{itemButton.website} login saved to clipboard"; }
private void Add_Passwords_Click(object sender, RoutedEventArgs e) { PasswordItem pass = new PasswordItem($"New Passwords", this); //new RoutedEventHandler[] { RenameItem, DeleteItem }); DirectoryTree.Items.Add(pass); }
public EditPasswordWindow(IDataStore ds, PasswordItem existing = null) { InitializeComponent(); vm = new EditPasswordWindowViewModel(this, ds, existing); DataContext = vm; }
/// <summary> /// 添加新的PasswordItem /// </summary> /// <param name="title"></param> /// <param name="img"></param> /// <param name="urlstr"></param> /// <param name="account"></param> /// <param name="password"></param> public void AddPasswordItem(string title, Byte[] img, string urlstr, string account, string password) { PasswordItem newItem = new PasswordItem(title, img, urlstr, account, password); this.allItems.Add(newItem); DB.Add(newItem); }
public static string Add(PasswordItem item, string json) { var items = Get(json); items.Add(item); return(JsonConvert.SerializeObject(items)); }
private void ApplyClick(object sender, RoutedEventArgs e) { PasswordItem item = PasswordList.SelectedItem as PasswordItem; if (item.Name == Name.Text && item.Login == Login.Text && item.Email == Email.Text && item.Icon == (ButtonImage.Tag as string) && item.Website == Website.Text && item.Notes == Notes.Text && item.Password == Password.Text) { PasswordForm.Visibility = Visibility.Hidden; SavedForm.Visibility = Visibility.Visible; TurnOffEditMode(); return; } item.Icon = ButtonImage.Tag as string; item.Name = Name.Text; item.Login = Login.Text; item.Email = Email.Text; item.Password = Password.Text; item.Website = Website.Text; item.Notes = Notes.Text; long toAdd = System.DateTime.Now.Ticks - item.EditDate.Ticks; item.EditDate = item.EditDate.Add(new TimeSpan(toAdd)); //http://drwpf.com/blog/2008/10/20/itemscontrol-e-is-for-editable-collection/ var itemToAdd = new PasswordItem(item); (this.DataContext as Passwords).Remove(PasswordList.SelectedItem as PasswordItem); (this.DataContext as Passwords).Add(itemToAdd); PasswordList.SelectedItem = itemToAdd; PasswordForm.Visibility = Visibility.Hidden; SavedForm.Visibility = Visibility.Visible; ButtonImage.Source = null; ButtonImage.Tag = null; TurnOffEditMode(); }
public static void UpdatePasswordItem(PasswordItem passwordItem) { PmerDbContext dbContext = new PmerDbContext(); dbContext.PasswordItems.Update(passwordItem); dbContext.SaveChanges(); }
private void Test() { IDataStore client = new SQLiteDataStore("test.db", "test", false); client.Open(); var pwd = new PasswordItem() { Name = "test", Username = "******", Password = "******" }; (var passwords, var entries) = GetData(client); client.AddPassword(pwd); client.AddEntry(new Entry() { Name = "test", CredentialId = pwd.ID }); (passwords, entries) = GetData(client); client.DeletePassword(pwd); (passwords, entries) = GetData(client); }
/// <summary> /// 将添加的密码项插入表中 /// </summary> /// <param name="passwordItem"></param> public static void InsertPasswordItem(PasswordItem passwordItem) { PmerDbContext dbContext = new PmerDbContext(); // 修改过 dbContext.PasswordItems.Add(passwordItem); dbContext.SaveChanges(); }
/// <summary> /// 删除置顶 Id 的密码项 /// </summary> /// <param name="id">密码项目的 Id</param> public static void DeletePasswordItem(int id) { PmerDbContext dbContext = new PmerDbContext(); PasswordItem passwordItem = dbContext.PasswordItems.Find(id); dbContext.PasswordItems.Remove(passwordItem); dbContext.SaveChanges(); }
/// <summary> /// 根据密码名查询密码 /// </summary> /// <param name="passwordName"></param> /// <returns>查询成功返回该密码项,失败返回 null</returns> public static PasswordItem SearchPasswordByName(string passwordName) { PmerDbContext dbContext = new PmerDbContext(); // 忽略大小写比较,本应该使用 string.Equals(str1,str2,System.StringComparison.OrdinalIgnoreCase) // 但 Linq 中不支持 StringComparison.OrdinalIgnoreCase PasswordItem retPassword = dbContext.PasswordItems.SingleOrDefault(pw => pw.Title.ToLower().Equals(passwordName.ToLower())); return(retPassword); }
private void AddClick(object sender, RoutedEventArgs e) { PasswordItem pass = new PasswordItem(System.DateTime.Now); (this.DataContext as Passwords).Add(pass); PasswordList.SelectedItem = pass; PasswordForm.Visibility = Visibility.Visible; SavedForm.Visibility = Visibility.Hidden; TurnOnEditMode(); }
public void UpdatePassword(PasswordItem i) { string cmd = string.Format(cUpdatePassword, TablePasswords, i.ID, SQLUtils.SQLEncode(i.Name), SQLUtils.SQLEncode(i.Username), SQLUtils.SQLEncode(i.Password) ); client.ExecuteNonQuery(cmd); }
public void AddPassword(PasswordItem i) { string cmd = string.Format(cAddPassword, TablePasswords, SQLUtils.SQLEncode(i.Name), SQLUtils.SQLEncode(i.Username), SQLUtils.SQLEncode(i.Password) ); client.ExecuteNonQuery(cmd); i.ID = SQLUtils.GetLastInsertRow(client); }
/// <summary> /// PWItemViewModel的构造函数 /// 从数据库中加载数据 /// </summary> public PWItemViewModel() { List <PasswordItem> itemList = DB.GetAllItems(); foreach (var item in itemList) { item.Password = Crypto.Decrypt(item.Password); allItems.Add(item); } this.selectedItem = null; }
/// <summary> /// 更新PasswordItem /// </summary> /// <param name="title"></param> /// <param name="img"></param> /// <param name="urlstr"></param> /// <param name="account"></param> /// <param name="password"></param> public void UpdatePasswordItem(string title, Byte[] img, string urlstr, string account, string password) { if (this.selectedItem != null) { this.selectedItem.Title = title; this.selectedItem.Img = img; this.selectedItem.Urlstr = urlstr; this.selectedItem.Account = account; this.selectedItem.Password = password; DB.Update(this.selectedItem); this.selectedItem = null; } }
private void button_Click_ShowPassword(object sender, RoutedEventArgs e) { PasswordItem itemButton = GetPasswordItem(sender); if (itemButton.Password == "******") { itemButton.Password = Passwords.First(x => x.ID == itemButton.id).Password; } else { itemButton.Password = "******"; } }
public IEnumerable <ElementsGroup> GetSettings() { var items = new List <Element>(); var username = new TextItem("username", "Username"); var password = new PasswordItem("password", "Password"); var loginButton = new ButtonItem("loginButton", "Login"); var logoutButton = new ButtonItem("logoutButton", "Logout"); switch (showLabel) { case Label.ShowNothing: items.Add(username); items.Add(password); items.Add(loginButton); break; case Label.ShowLoginOk: var label = new LabelItem("label", "You are now logged in!"); items.Add(logoutButton); items.Add(label); break; case Label.ShowLoginFailed: label = new LabelItem("label", "Login failed"); items.Add(username); items.Add(password); items.Add(loginButton); items.Add(label); break; case Label.ShowLogoutOk: label = new LabelItem("label", "You have logged out"); items.Add(username); items.Add(password); items.Add(loginButton); items.Add(label); break; default: throw new ArgumentOutOfRangeException(); } var settings = new ElementsGroup("settings", "", items.ToArray()); return(new[] { settings, }); }
private void button_Click_CopyPassword(object sender, RoutedEventArgs e) { PasswordItem itemButton = GetPasswordItem(sender); if (itemButton.Password == "******") { Clipboard.SetText(Passwords.First(x => x.ID == itemButton.id).Password); } else { Clipboard.SetText(itemButton.Password); } textBlock.Text = $"{itemButton.website} password saved to clipboard"; }
public IActionResult Index() { PasswordItem item = new PasswordItem { Status = PasswordStatus.Initialization }; if (_db.Settings.Count() != 0) { var setting = _db.Settings.First(); ViewBag.SettingStatus = setting.SelectionStatus; } return(View("Index", item)); }
public EditPasswordWindowViewModel(EditPasswordWindow window, IDataStore ds, PasswordItem existing = null) { this.window = window; Cancelled = true; isEdit = existing != null; this.ds = ds; if (isEdit) { this.existing = existing; Name = existing.Name; Username = existing.Username; Password = existing.Password; } }
private void TryAdd() { if (logins.Count == 0 && passwords.Count == 0) { var pwd = new PasswordItem() { Name = "test", Username = "******", Password = "******" }; ds.AddPassword(pwd); ds.AddEntry(new Entry() { Name = "test", CredentialId = pwd.ID }); LoadLists(); } }
/// <summary> /// Create a new password item editor /// and viewer window instance. /// </summary> /// <param name="item">Init the editor values with this item</param> public PassItemEditor(PasswordItem item) { InitializeComponent(); //View model initialisation this.vm = new PassItemEditorViewModel(item); this.DataContext = this.vm; //Inital values this.passwordIsVisible = false; this.PassTextBox.Visibility = Visibility.Hidden; //Set the inital password text value this.PassBox.Password = this.vm.Password; //Check if the inital input is valid this.ValidateEditorItem(); }
public List <PasswordItem> GetPasswords() { var results = client.ExecuteSelect("select * from " + TablePasswords); List <PasswordItem> passwords = new List <PasswordItem>(); foreach (DataRow r in results.Rows) { var pwd = new PasswordItem(); pwd.ID = GetValue <int>(r["Id"]); pwd.Name = GetValue <string>(r["Name"]); pwd.Username = GetValue <string>(r["Username"]); pwd.Password = GetValue <string>(r["Password"]); passwords.Add(pwd); } return(passwords); }
async Task SaveToLocal() { try { var item = new PasswordItem(InputTitle.Text, InputPassword.Text); var json = await SecureStorage.GetAsync("passwords"); var result = StorageService.Add(item, json); await SecureStorage.SetAsync("passwords", result); await Navigation.PopAsync(); } catch { await DisplayAlert( "Ops!", "This device does not support secure storage", "OK"); } }
public AbstractDirectoryTreeItem TurnIntoTreeView(Page1 page) { AbstractDirectoryTreeItem item; if (Data == null) { item = new DirectoryItem(Name, page); } else if (Data is byte[]) { item = new ImageItem(Name, page, Data as byte[]); } else if (Data is List <PasswordData> ) { item = new PasswordItem(Name, page) { PassowrdList = Data as List <PasswordData> }; foreach (var pass in (item as PasswordItem).PassowrdList) { if (pass.SerializedBitmap != null) { pass.IconImage = new BitmapImage(); pass.IconImage.FromBytes(pass.SerializedBitmap); } } } else { throw new ArgumentException(); } foreach (var child in Children) { item.Items.Add(child.TurnIntoTreeView(page)); } return(item); }
public List <PasswordItem> GetPasswordItems(byte[] keyPassword) { List <PasswordItem> passwordItems = new List <PasswordItem>(); cmd.CommandText = "SELECT * FROM " + pwTableName; SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { PasswordItem passwordItem = new PasswordItem(); passwordItem.Id = (Int64)reader["id"]; passwordItem.Title = (string)reader["title"]; passwordItem.Account = (string)reader["account"]; string cipherText = (string)reader["password"]; passwordItem.Password = Encryptor.AESDecrypt(cipherText, keyPassword); passwordItem.Website = (string)reader["website"]; passwordItem.Avatar = (string)reader["avatar"]; passwordItems.Add(passwordItem); } return(passwordItems); }
public IActionResult VerifyPassword(PasswordItem item) { var passwordStatus = selectionService.ValidatePassword(item); if (passwordStatus == PasswordStatus.Success) { InitializeViewBugs(); int?credentialID = credentialService.GetCredentialIDByPassword(item.Password); return(RedirectToAction("SelectCandidate", "Selection", new { credentialID = credentialID, candidateIndex = 1 })); } else if (passwordStatus == PasswordStatus.DoubleLogin) { ModelState.AddModelError("doublepassword", "Այս ծածկագիրը արդեն կիրառվել է ընտրություն իրականացնելու համար:"); item.Password = String.Empty; return(View("Index", item)); } else { ModelState.AddModelError("wrongpassword", "Ծածկագիրը սխալ է"); item.Password = String.Empty; return(View("Index", item)); } }