├── TODO.md ├── CHANGELOG.md ├── src └── Cviebrock │ └── ArtisanHash │ ├── Commands │ ├── BaseCommand.php │ ├── MakeHashCommand.php │ └── CheckHashCommand.php │ └── ArtisanHashServiceProvider.php ├── phpunit.xml ├── composer.json ├── LICENSE └── README.md /TODO.md: -------------------------------------------------------------------------------- 1 | # Todo 2 | 3 | - [ ] Write tests -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## 1.0.1 - 25-Apr-2014 4 | 5 | - Minor tweaks. 6 | 7 | 8 | ## 1.0.0 - 25-Apr-2014 9 | 10 | - Initial release. 11 | -------------------------------------------------------------------------------- /src/Cviebrock/ArtisanHash/Commands/BaseCommand.php: -------------------------------------------------------------------------------- 1 | hasher = \App::make('hash'); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cviebrock/artisan-hash", 3 | "description": "Adds Artisan tasks to Laravel to work with password hashes from the CLI.", 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "Colin Viebrock", 8 | "email": "colin@viebrock.ca" 9 | } 10 | ], 11 | "require": { 12 | "php": ">=5.4.0", 13 | "illuminate/support": "4.*", 14 | "illuminate/hashing": "4.*" 15 | }, 16 | "require-dev": { 17 | "phpunit/phpunit": "3.7.*" 18 | }, 19 | "autoload": { 20 | "psr-0": { 21 | "Cviebrock\\ArtisanHash": "src/" 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Colin Viebrock 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 all 13 | 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 THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /src/Cviebrock/ArtisanHash/Commands/MakeHashCommand.php: -------------------------------------------------------------------------------- 1 | argument('string') ?: $this->secret('Enter the plaintext string to hash:', null); 29 | if (!$string) 30 | { 31 | $this->error('No string given.'); 32 | return; 33 | } 34 | 35 | $this->info( $this->hasher->make($string) ); 36 | 37 | } 38 | 39 | /** 40 | * Get the console command arguments. 41 | * 42 | * @return array 43 | */ 44 | protected function getArguments() 45 | { 46 | return array( 47 | array('string', InputArgument::OPTIONAL, 'The plaintext string to hash.'), 48 | ); 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /src/Cviebrock/ArtisanHash/ArtisanHashServiceProvider.php: -------------------------------------------------------------------------------- 1 | package('cviebrock/artisan-hash'); 23 | } 24 | 25 | /** 26 | * Register the commands 27 | * 28 | * @return void 29 | */ 30 | public function register() 31 | { 32 | 33 | foreach(array( 34 | 'MakeHash', 35 | 'CheckHash', 36 | ) as $command) 37 | { 38 | $this->{"register$command"}(); 39 | } 40 | } 41 | 42 | /** 43 | * Register the hash::make command 44 | */ 45 | protected function registerMakeHash() 46 | { 47 | $this->app['artisan-hash.make'] = $this->app->share(function($app) 48 | { 49 | return new MakeHashCommand; 50 | }); 51 | 52 | $this->commands('artisan-hash.make'); 53 | } 54 | 55 | /** 56 | * Register the hash::check command 57 | */ 58 | protected function registerCheckHash() 59 | { 60 | $this->app['artisan-hash.check'] = $this->app->share(function($app) 61 | { 62 | return new CheckHashCommand; 63 | }); 64 | 65 | $this->commands('artisan-hash.check'); 66 | } 67 | 68 | /** 69 | * Get the services provided by the provider. 70 | * 71 | * @return array 72 | */ 73 | public function provides() 74 | { 75 | return array(); 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /src/Cviebrock/ArtisanHash/Commands/CheckHashCommand.php: -------------------------------------------------------------------------------- 1 | argument('hash') ?: $this->secret('Enter the hash:', null); 30 | if (!$hash) 31 | { 32 | $this->error('No hash given.'); 33 | return; 34 | } 35 | 36 | 37 | $string = $this->argument('string') ?: $this->secret('Enter the plaintext string to check:', null); 38 | if (!$string) 39 | { 40 | $this->error('No string given.'); 41 | return; 42 | } 43 | 44 | if ( !$this->hasher->check($string, $hash) ) 45 | { 46 | $this->error('Hash does not match.'); 47 | return; 48 | } 49 | 50 | 51 | $this->info('Hash matches.'); 52 | if ( $this->hasher->needsRehash($hash) ) 53 | { 54 | $this->info('Your hash needs to be rehashed.'); 55 | } 56 | 57 | } 58 | 59 | /** 60 | * Get the console command arguments. 61 | * 62 | * @return array 63 | */ 64 | protected function getArguments() 65 | { 66 | return array( 67 | array('hash', InputArgument::OPTIONAL, 'The hash to check against.'), 68 | array('string', InputArgument::OPTIONAL, 'The plaintext string to check.'), 69 | ); 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # artisan-hash 2 | 3 | Adds Artisan tasks to Laravel to work with password hashes from the CLI. 4 | 5 | [![Latest Stable Version](https://poser.pugx.org/cviebrock/artisan-hash/v/stable.png)](https://packagist.org/packages/cviebrock/artisan-hash) 6 | [![Total Downloads](https://poser.pugx.org/cviebrock/artisan-hash/downloads.png)](https://packagist.org/packages/cviebrock/artisan-hash) 7 | 8 | * [Installation](#installation) 9 | * [Usage](#usage) 10 | * [Bugs, Suggestions and Contributions](#bugs) 11 | * [Copyright and License](#copyright) 12 | 13 | 14 | 15 | 16 | ## Installation 17 | 18 | First, add the package to the `require-dev` attribute of your `composer.json` file: 19 | 20 | ```json 21 | { 22 | "require": { 23 | "cviebrock/artisan-hash": "1.*" 24 | }, 25 | } 26 | ``` 27 | 28 | > You could add it to the `require` section instead, but you likely only need this during development. 29 | 30 | Next, update Composer from the Terminal: 31 | 32 | ```sh 33 | composer update --dev 34 | ``` 35 | 36 | Once this operation completes, add the service provider. Open `app/config/app.php`, and add a new item to the providers array. 37 | 38 | ``` 39 | 'Cviebrock\ArtisanHash\ArtisanHashServiceProvider' 40 | ``` 41 | 42 | That's it! Run the `artisan` command from the Terminal to see the new commands. 43 | 44 | ```sh 45 | php artisan 46 | ``` 47 | 48 | 49 | 50 | 51 | ## Usage 52 | 53 | ### hash:make 54 | 55 | This will hash the given plaintext string and output the hash to the console. If you don't provide a string, you will be asked to enter one (this will keep the plaintext string out of your shell history). 56 | 57 | ```sh 58 | $ php artisan hash:make foo 59 | $2y$08$3nq5mD1faNAPUdyt72yyqOTRl/OIrizhQ84EnH1kbouC/8ud31smW 60 | ``` 61 | 62 | ### hash:check 63 | 64 | This will compare a given hash to a plaintext string and see if they match. 65 | 66 | ```sh 67 | $ php artisan hash:check '$2y$08$3nq5mD1faNAPUdyt72yyqOTRl/OIrizhQ84EnH1kbouC/8ud31smW' foo 68 | Hash matches. 69 | ``` 70 | 71 | > Note that if the hash contains dollar signs -- as it likely will -- you will need to escape them in your shell. The easiest way is just to surround the hash in single quotes, or don't provide the hash via the command and use the prompt. 72 | 73 | The command will also check if the hash needs rehashing. 74 | 75 | ```sh 76 | $ php artisan hash:check '$1$stCkrNrE$W92vGH25VHnLK.kDBmZwz0' foo 77 | Hash matches. 78 | Your hash needs to be rehashed. 79 | ``` 80 | 81 | 82 | 83 | 84 | ## Bugs, Suggestions and Contributions 85 | 86 | Please use Github for bugs, comments, suggestions. 87 | 88 | 1. Fork the project. 89 | 2. Create your bugfix/feature branch and write your (well-commented) code. 90 | 3. Create unit tests for your code: 91 | - Run `composer install --dev` in the root directory to install required testing packages. 92 | - Add your test methods to `artisan-hash/tests/`. 93 | - Run `vendor/bin/phpunit` to the new (and all previous) tests and make sure everything passes. 94 | 3. Commit your changes (and your tests) and push to your branch. 95 | 4. Create a new pull request against the artisan-hash `develop` branch. 96 | 97 | **Please note that you must create your pull request against the `develop` branch.** 98 | 99 | 100 | 101 | 102 | ## Copyright and License 103 | 104 | [artisan-hash](https://github.com/cviebrock/artisan-hash) was written by Colin Viebrock and released under the MIT License. See the LICENSE file for details. 105 | 106 | Copyright 2014 Colin Viebrock 107 | --------------------------------------------------------------------------------