Skip to Content Skip to Menu

[SOLVED] Trying to Verify Current Password CB field against Joomla user password

10 years 7 months ago - 10 years 7 months ago #242421 by prestoproducts
I am trying to create a trigger which will verify that the user has entered the correct current password for their account before updating a new password. To do this I have created a cb user field titled ‘cb_currentpass’ and my plan is to trigger it to verify the value matches the joomla user password.

The problem that I have found is that the version of Joomla that I am using is not saving the user passwords with a salted, hashed and md5 encrypted value. Rather, the password saved in the database looks more like this:

$P$DzLyqLU1RaXHyqAtR5JJSLleP76d7y/

I have looked into this password and it appears to be the new dcrypt method that Joomla is now using. I have tried a handful of ways to find out how Joomla creates this value, but no luck. So my first question is can you explain how I can take the plaintext value and get the new style password?

My second question is whether or not there is an easier way to approach this issue. I have not seen any such plugin, but I figured I would ask as you may have some type of plan in mind to validate a current password prior to updating the profile. Thank you for the help in this research.
Last edit: 10 years 7 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48478
  • Thanks: 8282
  • Karma: 1443
10 years 7 months ago #242449 by krileon

I am trying to create a trigger which will verify that the user has entered the correct current password for their account before updating a new password. To do this I have created a cb user field titled ‘cb_currentpass’ and my plan is to trigger it to verify the value matches the joomla user password.

Is there any specific reason you need this? Joomla already handles password matching on login, etc.. It seams redundant to have to double check this. Also no there is no way to do this with a Conditional in an action. You need to call CB user object or Joomla API to validate a password. it is impossible to do a direct comparison due to encryption (very good thing). If you have a CB user object then the below for example will validate a password (returning true or false).

Code:
$validPassword = $user->verifyPassword( $plainTextPassword );

So my first question is can you explain how I can take the plaintext value and get the new style password?

Edit the user, add the plaintext password to their password field, then save the user. That's the absolute most easy way to do it.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

10 years 7 months ago #242462 by prestoproducts
The reason I have to do this is because of a client's requirements. Here is a screenshot of what they are after:

The idea is that when the user enters a value into the current password field I will either have an AJAX script fire onBlur event and check the value matches in order to allow the password to be updated by the user. Either that, or before the profile is updated the check will take place using CB Auto Actions.

Ultimately I need a way to take the plaintext password and turn it into Joomla's format for password encryption. In the past I could do something like this to achieve this goal:
Code:
$pass = ‘plain-text-user-input’; $userIdValue =& JFactory::getUser(); $fullPassword = $userIdValue->password; //pull salt value from password for user $separatedPassword = explode(":", $fullPassword); $saltKey = $separatedPassword[1]; //create new password value to query $saltyPass = $pass.$saltKey; $md5saltyPass = md5($saltyPass); $completePassToQuery = $md5saltyPass.':'.$saltKey; //take password field and query it to determine if it matches

The problem is that Joomla no longer seems to create passwords in this fashion. So my question is how are Joomla passwords now generated?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48478
  • Thanks: 8282
  • Karma: 1443
10 years 7 months ago #242466 by krileon
You can generate a Joomla password from plaintext using a function call on a CB user object. Example as follows.

Code:
$password = $user->hashAndSaltPassword( $plainTextPassword );

With my above reply you can also verify a plaintext password.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

10 years 7 months ago #242478 by prestoproducts
I believe I am getting closer to understanding this. When I run the following script I get a hashed value of 123456
Code:
<? Global $_CB_framework; $myId = $_CB_framework->myId(); $user =& CBuser::getUserDataInstance( $myId ); $plainTextPassword = '123456'; $password = $user->hashAndSaltPassword( $plainTextPassword ); echo $password; ?>

The value reads as:

$P$D9tQZwh3z/ujaehC2Mh7dy8t6ayvDS0

Now, when I look at the password that is stored for a user with a 123456 password, it looks like this:

$P$D6x5Ydgjjcq/T2Z.p0ghEcjQSOYb3H0

Why don't they match?

Please Log in or Create an account to join the conversation.

10 years 7 months ago #242480 by prestoproducts
Wow... it even gets crazier in that every time I refresh the script I get a different value. How can I possibly match it this way?

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum