0

I have an existing database.

users :
username => varchar
password => md5 hashing

I am new to laravel, I was try to create simple login and register from laravel docs, thats work fine, but in docs are create for laravel, now I want to create same login/register but with existing datas.

I was read some Question from How to use SHA1 encryption instead of BCrypt in Laravel 4? but I dont understand how to use it.

any adv?

sory for my bad grammer.

Community
  • 1
  • 1
Anggagewor
  • 167
  • 1
  • 2
  • 15
  • What you don't understand there exactly ? he wrote the whole steps you need to do and even wrote the code there for you all you need to do is copy-paste. – Gal Sisso Sep 19 '15 at 11:40
  • `routes`. I was done for copy-paste. but i dont know what to do next.. i realy new in laravel. – Anggagewor Sep 19 '15 at 13:08
  • 1
    What routes? you should use laravel the same.just change `hash('sha1', $value);` to `md5` and then you'll have laravel authentication using md5. – Gal Sisso Sep 19 '15 at 13:57
  • routes like `Route::get('auth/login', 'Auth\AuthController@getLogin');`. sory if my question make you confused. – Anggagewor Sep 19 '15 at 14:51
  • Do you mean to have previous passwords in the form of md5 hash? – Aditya Giri Sep 20 '15 at 04:44
  • I'm sorry but I still don't get what is the issue,there are many sites that will teach you how to work with the framework,some even explain how to build a website from 0 using laravel.I personally recommend on [Laracasts - Laravel 5 Fundamentals](https://laracasts.com/series/laravel-5-fundamentals) it will teach you the basics for free. – Gal Sisso Sep 20 '15 at 17:56

1 Answers1

3

I'll Try to answer my question. I take it from Facebook Group Laravel Indonesia

  • Create directory app/libraries

  • Add app/libraries to composer.json

    "classmap": ["database","app/libraries"],

  • Create MD5Hasher.php in app/libraries

    <?php    
    namespace App\Libraries;        
    use Illuminate\Contracts\Hashing\Hasher as HasherContract;
    
    class MD5Hasher implements HasherContract {
    
    public function make($value, array $options = array()) {
    $value = env('SALT', '').$value;
    return md5($value);
    }
    
    public function check($value, $hashedValue, array $options = array()) {
    return $this->make($value) === $hashedValue;
    }
    
    public function needsRehash($hashedValue, array $options = array()) {
    return false;
    }
    
    }
    
  • Create MD5HashServiceProvider.php in app/libraries

    <?php
    
    namespace App\Libraries;
    
    use Illuminate\Support\ServiceProvider;
    
    class MD5HashServiceProvider extends ServiceProvider {
    
    /**
    * Register the service provider.
    *
    * @return void
    */
    public function register() {
    $this->app['hash'] = $this->app->share(function () {
    return new MD5Hasher();
    });
    
    }
    
    /**
    * Get the services provided by the provider.
    *
    * @return array
    */
    public function provides() {
    return array('hash');
    }
    
    }
    
  • in config/app.php

    Find Illuminate\Hashing\HashServiceProvider::class,

    Change to App\Libraries\MD5HashServiceProvider::class,

  • in AuthController.php

    Add protected $username = 'username';

    return Validator::make($data, [
                //'name' => 'required|max:255',
                'username' => 'required',
                'password' => 'required|confirmed|min:5',
            ]);
    
    return User::create([
                //'name' => $data['name'],
                'username' => $data['username'],
                'password' => md5($data['password']),
            ]);
    
  • in App\Users.php

    Change protected $fillable = ['name', 'email', 'password'];

    To protected $fillable = ['username', 'password'];

  • Don't forget to run composer dumpautoload

I don't know what I am doing is right or not.

Regard

Anggagewor
  • 167
  • 1
  • 2
  • 15
  • "classmap": ["database","app/libraries"], where in composer.json ? @Anggagewor "autoload": { "classmap": [ "database/seeds", "database/factories" ], "psr-4": { "App\\": "app/" } }, here ? – Ashfaq Apr 05 '18 at 00:41