1

I need to sync my user database with another user database; the other user database uses SHA1 as hash with USERNAME:PASSWORD as algorithm.
Is there a way to rehash it that I can store it in the database?

Do you have any idea?

It should be possible to edit the user/*/edit form and hash the password on my own and save it afterwards, or am I wrong? If it can work, can you give me any tip on how?

I did a bit reasearch about editing the user_profile_form (for example: Making a username/password syncronization scheme - D7) where I read that $form_state['values']['pass'] could give me the password in plain text to hash it on my own and insert it into my database.
Afterwards I directly tried to investigate more and tried to displa me the password with dpm($form_state['values']['pass']);, but I noticed (controlled with dpm($form, '$form info for $form_id '.$form_id);) that theres no values.

How can I get the plain text password in user_profile_form or is it impossible and only possible in user_register_form (as stated in topic above). In my user_registe_form is no password entered, because I use the method to get a link with E-Mail were you can login one time and change the password with user_profile_form.

Thank you!

2

There are a couple of ways to do this.

You need to look into the function user_authenticate.

In that function, you will see there is a call to variable_set() that sets the path to the variable password_inc. So, basically you could overide the path of this file, change it so it points to your custom password.inc, in a custom module out of core code. In that file you would redefine the same functions with your own logic.

There could well be a simpler way of doing this. I know single-sign on can also be easily done with Drupal 7 as there are functions that make this easily available out of the box. Maybe look at OpenID code or other contrib modules if you choose to use that path.

Good-luck!

  • I guess this would overrides the password encryption from Drupal, am I right? Wouldn't the PhpBB3 Drupal Bridge stop working after this change? I definitly need the password in the above described algorithm, so I can't choose Open ID (also I think PhpBB3 Drupal Bridge wouldn't work with Open ID either). Everything is kinda complicated, though. – Leandros Aug 16 '12 at 1:45
  • The true pain in the ass is, not to hack the Drupal Core, it would be so easy with some hacks. ;) – Leandros Aug 16 '12 at 3:15
  • password.inc is Drupal's way to have a pluggable password mechanism so that you can implement your own without hacking core. That file contains a list of functions to hash a password and later on verify it, you just need to make sure that the functions that drupal expects are in there then you can do whatever you want within. – Berdir Aug 16 '12 at 10:04
  • 1
    @Leandros this depends on how phpBB / Drupal bridge is coded. If a user signed on to Drupal is automatically logged in to phpBB, there are chances it would work but I can't say without looking at the code. – stefgosselin Aug 16 '12 at 10:10
  • I solved it. A big thanks so stefgosselin, this worked, I put my hash algorithm in user_hash_password, hash it with my algorithm and put it into db and use the stock Drupal way to hash it for Drupal and insert it intp Drupal db. The only trick I used, is that I assigned $password to another variable, because it seemed $password can only be used once. This doesnt effect the Bridge, she is working fine. – Leandros Aug 16 '12 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.