I make the site not on the drupal, and you need to make the user login. Database from Dryupal 7. How to encrypt the password for verification?

Drupal 7

  • drooling :)))) - Artem
  • So can it call the creation functions of a user of Drupal? - zb '

1 answer 1

If the drupal is installed and the engine itself works, then something like this can be done:

  1. we connect drupal

    $path_to_drupal = "/var/www/DRUPAL_FOLDER"; define('DRUPAL_ROOT', $path_to_drupal); //устанавливаем константу DRUPAL_ROOT так как она используется в бутстрап require_once dirname(__FILE__) . '/includes/bootstrap.inc';//подключаем сам бутстрап require_once dirname(__FILE__) . '/includes/password.inc';// в этом файле собраны все функции для работы с паролями drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // стартуем друпал 
  2. Next, select from the user base

     $query = db_select('users', 'u'); $query ->condition('u.uid', 0, '<>') ->fields('u', array('uid', 'pass')); $result = $query->execute(); 
  3. We pull password hashes and compare with what came from the form

     foreach ($result as $users) { $stored_hash = $users->pass; $new_pass = $_POST['form_password_field'];// тут то, что пришло с формы $hash = _password_crypt('sha512', $new_pass, $stored_hash); if ($hash && $stored_hash == $hash) { echo 'PASSWORD CORRECTLY'; } else { echo 'YOU WRONG'; } } 

If the drupal is not installed, but you need to use its user base, then from /includes/password.inc rewrite the _password_crypt and user_check_password , substituting our variables.

salt is in the configuration file settings.php