Password Checker at https://gec.im/passwords/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.9 KiB

  1. #!/usr/bin/env perl
  2. #
  3. # Copyright (c) 2014 Mr. Gecko's Media (James Coleman). http:#mrgeckosmedia.com/
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. # THE SOFTWARE.
  22. #
  23. use Digest::SHA1 qw(sha1 sha1_hex);
  24. #DBD::mysql
  25. use DBI;
  26. use POSIX;
  27. use DateTime;
  28. sub trim($) {
  29. my $string = shift;
  30. $string =~ s/^\s+//;
  31. $string =~ s/\s+$//;
  32. $string =~ s/^\t+//;
  33. $string =~ s/\t+$//;
  34. $string =~ s/^\s+//;
  35. $string =~ s/\s+$//;
  36. $string =~ s/^\t+//;
  37. $string =~ s/\t+$//;
  38. $string =~ s/\n//g;
  39. $string =~ s/\r//g;
  40. return $string;
  41. }
  42. $dbHost = "127.0.0.1";
  43. $dbName = "passwords";
  44. $dbUser = "root";
  45. $dbPassword = "password";
  46. $file = "/Users/grmrgecko/Desktop/passwords.csv";
  47. #print localtime(time).": Connecting to DataBase\n";
  48. $dbConnection = DBI->connect("DBI:mysql:$dbName;host=$dbHost", $dbUser, $dbPassword) || die "Could not connect to database: $DBI::errstr";
  49. open(passwords, $file);
  50. my $i=0;
  51. my $count=0;
  52. while (<passwords>) {
  53. chomp;
  54. $i++;
  55. my $sha1 = sha1_hex(trim($_));
  56. print $i.": ".$sha1."\n";
  57. my $result = $dbConnection->prepare("SELECT * FROM `sha1` WHERE `hash`=?");
  58. $result->execute($sha1);
  59. my $exists = $result->fetchrow_hashref();
  60. if ($exists!=undef) {
  61. $result->finish();
  62. next;
  63. }
  64. $result->finish();
  65. my $result = $dbConnection->prepare("INSERT INTO `hash` (`hash`,`leak`) VALUES (?,'Email Database')");
  66. $result->execute($sha1);
  67. $result->finish();
  68. $count++;
  69. if ($count%10000==0) {
  70. my $result = $dbConnection->prepare("INSERT INTO `sha1` (`hash`,`leak`) SELECT `hash`,`leak` FROM `hash`");
  71. $result->execute();
  72. $result->finish();
  73. my $result = $dbConnection->prepare("DELETE FROM `hash`");
  74. $result->execute();
  75. $result->finish();
  76. }
  77. }
  78. my $result = $dbConnection->prepare("INSERT INTO `sha1` (`hash`,`leak`) SELECT `hash`,`leak` FROM `hash`");
  79. $result->execute();
  80. $result->finish();
  81. my $result = $dbConnection->prepare("DELETE FROM `hash`");
  82. $result->execute();
  83. $result->finish();
  84. close(passwords);
  85. $dbConnection->disconnect();