Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- // Set the exception handler
- set_exception_handler(function(Exception $e){
- print "-- " .$e->getMessage();
- });
- // Only run in the CLI
- if(php_sapi_name() != 'cli'){
- throw new Exception('This script is accessible only through the command line!');
- }
- // Get the passed arguments in the command line
- $arguments = $_SERVER['argv'];
- unset($arguments[0]);
- if(count($arguments) < 1){
- throw new Exception('You need to provide some keywords to help create more promising passwords!');
- }
- // Ready the keywords list
- $keywords = implode(' ', $arguments);
- $keywords = trim($keywords, ',');
- $keywords = explode(',', $keywords);
- $keywords = array_map('trim', $keywords);
- $keywords = array_unique($keywords);
- if(!count($keywords)){
- throw new Exception('No keywords were provided!');
- }
- // If one of the keywords is an email address
- foreach($keywords as $i => $keyword){
- if(strpos($keyword, '@')){
- unset($keywords[$i]);
- // Drop the trailing service provider domain name, eg: xx@gmail.com ~> xx
- $keywords[] = explode('@', $keyword)[0];
- }
- }
- /////////////////////////
- // A list of common numerical combinations used in passwords
- $numericPasswordsCombinations = ['0123', '0123456', '0123456789', 9876543210, 123, 321, 123456, 654321, 147852369,
- 369852741, 159357, 951753, 456852, 789654321, 123654789, 112233, 445566, 778899, 112233445566, 985236,
- 147852, 14789632, 98741236, 36987412, 78963214, 47896321, 89632147, 563214789, 541236987, '01478963',
- '0147896325', '0987654321', 123456789];
- // Create the passwords
- // Probability #1: the password is one of the keywords!
- {
- $passwords = [];
- foreach($keywords as $keyword){
- $passwords[] = $keyword;
- // Try some other variants of the same keyword
- if(strpos($keyword, ' ')){
- $keywords[] = $passwords[] = str_replace(' ', '_', $keyword);
- $keywords[] = $passwords[] = str_replace(' ', '-', $keyword);
- }
- }
- }
- // Probability #2: one of the numerical combinations
- {
- $passwords += $numericPasswordsCombinations;
- }
- // Probability #3: a combination of the keywords and the numbers
- {
- foreach($numericPasswordsCombinations as $number){
- foreach($keywords as $keyword){
- $passwords[] = $keyword .'_' .$number;
- $passwords[] = $keyword .$number;
- $passwords[] = $number .$keyword;
- }
- }
- }
- // Create the passwords.txt file
- if(!@file_put_contents('passwords.txt', implode(PHP_EOL, $passwords))){
- throw new Exception('Passwords were generated, but cannot create the passwords.txt file!');
- }
- print 'Success! passwords.txt contains ' .count($passwords) .' password. Have fun!';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement