php - How to use SHA1 encryption instead of BCrypt in Laravel 4? -


i'm developing called aac (automatic account creator) game, it's site functions create accounts, players , several more things players. server supports sha1 , plain - totally unsafe. can't dive source code , make changes. if there's anyway use sha1 grateful. read bcrypt, it's great can't change source code suit bcrypt. managed put sha1 on registration this:

$password = $input['password']; $password = sha1($password); 

but can't login. doing wrong? seems laravel won't let me login.

i've got get_register , post_register, i've got get_login , post_login. need change in post_login make login or? hints?

i'm using laravel's php server (php artisan serve) , phpmyadmin on wamp. think laravel checks when checking db via auth::attempt method laravel doing form of hashing check current pw , logged in 1 check against each other.

you'll have rewrite hash module. laravel's ideas of following ioc , dependency injection concepts, it'll relatively easy.

first, create app/libraries folder , add composer's autoload.classmap:

"autoload": {     "classmap": [         // ...          "app/libraries"     ] }, 

now, it's time create our class. create shahasher class, implementing illuminate\hashing\hasherinterface. we'll need implement 3 methods: make, check , needsrehash.

note: on laravel 5, implement illuminate/contracts/hashing/hasher instead of illuminate\hashing\hasherinterface.

app/libraries/shahasher.php

class shahasher implements illuminate\hashing\hasherinterface {      /**      * hash given value.      *      * @param  string  $value      * @return array   $options      * @return string      */     public function make($value, array $options = array()) {         return hash('sha1', $value);     }      /**      * check given plain value against hash.      *      * @param  string  $value      * @param  string  $hashedvalue      * @param  array   $options      * @return bool      */     public function check($value, $hashedvalue, array $options = array()) {         return $this->make($value) === $hashedvalue;     }      /**      * check if given hash has been hashed using given options.      *      * @param  string  $hashedvalue      * @param  array   $options      * @return bool      */     public function needsrehash($hashedvalue, array $options = array()) {         return false;     }  } 

now have our class done, want used default, laravel. so, we'll create shahashserviceprovider, extending illuminate\support\serviceprovider, , register hash component:

app/libraries/shahashserviceprovider.php

class shahashserviceprovider extends illuminate\support\serviceprovider {      /**      * register service provider.      *      * @return void      */     public function register() {         $this->app['hash'] = $this->app->share(function () {             return new shahasher();         });      }      /**      * services provided provider.      *      * @return array      */     public function provides() {         return array('hash');     }  } 

cool, have make sure our app loads correct service provider. on app/config/app.php, under providers, remove following line:

'illuminate\hashing\hashserviceprovider', 

then, add one:

'shahashserviceprovider', 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -