tbenyon
Forum Replies Created
-
Forum: Plugins
In reply to: [External Login] Problem with Log InHey Ray,
No problem! Glad you got it all set up!
Well done π
Good luck with the project!
Tom
Forum: Plugins
In reply to: [External Login] Problem with Log InHey Ray,
Regarding the “Undefined index: role” I believe this is only a warning and not throwing an error but I may be wrong? This should not be displaying in the front end. If it is, you probably should make sure it doesn’t show these warnings on your production site.
I think this is because you haven’t set up table mapping for the role field in for the external database in the External Login settings.
We can test this is true by, setting it to a random field in your users table which should disregard this issue I think. Foe example, set it to the field that stores the username.To avoid this warning for the future I’ll also add some safeguards so that that data isn’t required.
Unless I misunderstood you though it does sound like the functionality is working as you would expect?
- User logs in with correct password from external database and gains access
- user logs out
- password is changed in external database
- User tries to log in with old (incorrect) password in WP and does not get logged in
- User uses the new (correct) external password to login and gains access to WP
Is this the flow you expected?
Thanks Ray,
Tom π
Forum: Plugins
In reply to: [External Login] Problem with Log InOk, so the real fix here is that I need to implement and publish those safeguards. I’ve added this on the project board for a new release.
In regard to your new query regarding stopping a user being created, I think this is not the solution to your problem. To function properly, WordPress has got to have the user stored. However, you’ll notice there is a setting that disables local login. This prevents any user from logging in with the local DB and forces the use of the external one. π
I’ll mark this ticket as resolved for now, but if you have further issues, please don’t hesitate to get back in contact.
If you don’t mind I’d be grateful if you could take the time to write a review or buy me a beer.
Thanks Ray,
Tom π
Forum: Plugins
In reply to: [External Login] Problem with Log InYeah, reading your message again. If it’s working for the first time now, and you remove that cock up discussed above does it now start to work?
Forum: Plugins
In reply to: [External Login] Problem with Log InHey Ray,
That is a cock up on my part. I put the
$user = false;in so I could quickly try to replicate the error you were seeing. That definitely needs removing!!! Apologies for wasting your time on this.It would be so much easier if we could screen share and resolve this together π Unfortunately not allowed to under the forum rules π
The development system uses Docker so it should be quick to try PHP 7.3 locally. I’ll be back! π
Forum: Plugins
In reply to: [External Login] Can’t LoginHey @julian45123,
Apologies for the delayed response. It’s been a busy week.
From looking at this the example you sent the solution is incredibly custom and uses an md5 hash as it’s core (not bcrypt).
When it ‘encrypts’ the password it is definitely doing it in a custom way. It appears to be hashing the typed in password then storing the a jumble of the hash where the second set of 16 characters are placed on the front and the first set at the back. It then uses a salt and a static key which is being used like a second salt.
You can still make this work with the plugin using a hook.
If you go to the FAQ and look at the exlog_hook_filter_authenticate_hash hook thereβs some instruction in there about how to write your custom hashing algorithm.Essentially you’ll have to replicate the logic that your custom setup uses to return true or false in the hook.
Forum: Plugins
In reply to: [External Login] Support for Redmine password hashHey @jamasi,
Apologies for the delayed response. Yes it can but just requires the use of a filter your end.
If you go to the FAQ and look at the
exlog_hook_filter_authenticate_hashhook there’s some instruction in there about how to write your custom hashing algorithm.I have not tested this code but yours would look something like this:
function myExlogHashAuthenticator($password, $hashFromDatabase, $username, $externalUserData) { // If getting the salt this way does not work you could hard code the salt here if it is safe to do so in your implementation $salt = exlog_get_option("external_login_option_db_salt"); $calculatedHashStep1 = hash('sha1', $password); $calculatedHashStep2 = hash('sha1', $salt . $calculatedHashStep1); return $hashFromDatabase == $calculatedHashStep2; } add_filter('exlog_hook_filter_authenticate_hash', 'myExlogHashAuthenticator', 10, 4);I’ve purposely written this out in a slightly longer format to make it easier to read.
Let me know how you get on π
Forum: Plugins
In reply to: [External Login] Old Service Loops Through Hashing 20 TimesHey @vcomgrp,
Apologies for the delayed response. Yes it can but just requires the use of a filter your end.
If you go to the FAQ and look at the
exlog_hook_filter_authenticate_hashhook there’s some instruction in there about how to write your custom hashing algorithm.I have not tested this code but yours would look something like this:
function myExlogHashAuthenticator($password, $hashFromDatabase, $username, $externalUserData) { $calculatedHash = $password; for ($i = 1; $i <= 20; $i++) { $calculatedHash = hash('sha512', $calculatedHash); } return $hashFromDatabase == $calculatedHash; } add_filter('exlog_hook_filter_authenticate_hash', 'myExlogHashAuthenticator', 10, 4);Let me know how you get on π
Forum: Plugins
In reply to: [External Login] Cant loginHey @dmsaurabh,
This could be due to a number of reasons.
Are you using mssql and you are either using a salting method where each user has their own salt OR you are using the EXLOG_HOOK_FILTER_AUTHENTICATE_HASH there is a bug at the moment that is going to be fixed soon.
If this is not the case, can you please start by checking you’ve definitely selected the correct hashing algorithm?
If this is all fine, the next thing I’ll ask you to do is to replace the following method in wp-content/plugins/external-login/login/validate_password.php:
function exlog_validate_password($password, $hash, $user_specific_salt) { error_log('EXLOG START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); error_log('EXLOG password-----'); error_log(var_export($password, true)); error_log('EXLOG password-----'); error_log(var_export($hash, true)); error_log('EXLOG User specific salt-----'); error_log(var_export($user_specific_salt, true)); $salt_method = exlog_get_option("external_login_option_db_salting_method"); $algorithm = exlog_get_option("external_login_option_hash_algorithm"); error_log('EXLOG external_login_option_db_salting_method-----'); error_log(var_export($salt_method, true)); error_log('EXLOG external_login_option_hash_algorithm-----'); error_log(var_export($algorithm, true)); $hash = exlog_should_lowercase_hex_hash($algorithm, $hash); if ($algorithm == "none") { return $password == $hash; } else if ($algorithm == "phpass") { return wp_check_password($password, $hash); } else if ($algorithm == "phpcrypt") { return crypt($password, $hash) == $hash; } else if ($algorithm == "bcrypt") { return password_verify($password, $hash); } else { if ($salt_method == 'none') { return exlog_hash_password($password, true) == $hash; } else if ($salt_method == 'all') { return exlog_hash_password($password, false, $user_specific_salt) == $hash; } else { return exlog_hash_password($password) == $hash; } } }If you then look in your error logs and share the output that will help us start to diagnose the issue further.
IMPORTANT Please make sure you only do this with a test user as we don’t want personal data shared in the forum!
Forum: Plugins
In reply to: [External Login] Problem with Log InApologies for the delayed response π
Sorry if this is too much information but by writing this all out may help you help me solve the problem if your technically minded but I’m mostly doing it to remind me of my thought process as I come back to look at this issue.
So the code we’re looking at is basically the oldest in the plugin. It comes from the article I’ve credited as being the original source for the concept. I can see better ways of handling this whole section but until I finish the work on bettering testing I don’t want to make large changes to this core logic as there are over 1000+ users depending on it for authentication of their apps.
I think that we can be happy that the following line is returning
false:$user = $userobj->get_data_by('login', $response['username']); // Does not return a WP_User object π
This is because it cannot determine a user from your WordPress database. This means the user with the username ‘fredbloggs’ does not exist in your users table in theuser_loginfield. However I believe you said it does so can you please double check this.The strange thing that I can’t replicate is that your code is throwing an error because the
IDdoes not exist on the $user property but althought this is true, I’ve not had any other users report this error blocking their login.I was wondering if you’re running a very old version of PHP but I’m not sure.
NEXT STEP:
Can you please replace this code block where I have added a couple of extra safeguards that may allow your implementation to function. It is the whole else if block:} else if ($response["exlog_authenticated"]) { // External user exists, try to load the user info from the WordPress user table $userobj = new WP_User(); error_log('EXLOG START>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); error_log('EXLOG resp >>>>'); error_log(var_export($response, true)); $user = $userobj->get_data_by('login', $response['username']); // Does not return a WP_User object π error_log('EXLOG user >>>>'); error_log(var_export($user, true)); $user = false; if ($user) { $user = new WP_User($user->ID); // Attempt to load up the user with that ID } $exlog_userdata = array( 'user_login' => $response['username'], 'first_name' => $response['first_name'], 'last_name' => $response['last_name'], 'user_pass' => $password, 'role' => $roles[0], 'user_email' => $response['email'], ); // If user does not exist if (!$user || $user->ID == 0) { // Setup the minimum required user information $new_user_id = wp_insert_user( $exlog_userdata ); // A new user has been created // Load the new user info $user = new WP_User ($new_user_id); error_log('EXLOG HERE1'); } else { $exlog_userdata['ID'] = $user->ID; add_filter('send_password_change_email', '__return_false'); // Prevent password update e-mail wp_update_user($exlog_userdata); error_log('EXLOG HERE2'); } $user->set_role($roles[0]); // Wipe out old roles // Add roles to user if more than one foreach ($roles as $role) { $user->add_role($role); } // Hook that passes user data on successful login do_action('exlog_hook_action_authenticated', $user, $exlog_userdata); error_log('EXLOG END>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); }Thank you for your patience,
Tom π
Forum: Plugins
In reply to: [External Login] Problem with Log InHey Ray (@raider1967),
Apologies for the delayed response. Been busy at work.
This is a new one to me. My first guess is that your not getting all the required data that WordPress deems necessary for a user. The first thing I’d ask you to check is that you’ve specified all the field mappings and they are correct in the external login settings.
If this doesn’t work, the next step would be for you to modify the code block your talking about to get some additional logs.
If you could modify this code in the plugin to get the additional logs and then share the information back with me here that’d be awesome.
IMPORTANT
- You probably don’t want to do this on your live site as real users data could end up in your logs.
- Make sure you use a test user for sharing the logs with me as I don’t want you sharing any personal information in the forum
} else if ($response["exlog_authenticated"]) { // External user exists, try to load the user info from the WordPress user table $userobj = new WP_User(); error_log('EXLOG START>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); error_log('EXLOG resp >>>>'); error_log(var_export($response, true)); $user = $userobj->get_data_by('login', $response['username']); // Does not return a WP_User object π error_log('EXLOG user >>>>'); error_log(var_export($user, true)); error_log('EXLOG END>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); $user = new WP_User($user->ID); // Attempt to load up the user with that IDThanks,
Tom π
Forum: Plugins
In reply to: [External Login] External database just as a “first time check”Hey @fefo1983,
Firstly thank you for the beer!!! Really appreciated π Made my day. You’ll be glad to know it will be spent on a BrewDog order π
So the plugin will achieve half of what you’re looking for and I think could potentially tie in nicely if you code the rest of the flow.
To break down your bullets to the three steps:
- This is achievable with the plugin. You would just set the plugin to not use a hashing algorithm so that the plain 4 digit code would be validated against the database
- Yes the plugin will create a user account, and it will use the 4 digit code as the password and hash that into the database. However, it does not have any functionality to force the user to change their password. I will talk about what you could to to solve this step below
- The plugin has a setting called migration mode that will solve this problem for you. It means that if the user already exists in the local database they will not be searched for again in the external database.
A way you could solve the missing part of the flow you want to achieve…
The plugin uses WordPress’ ‘authenticate’ hook to validate and return the user to log them in. You could add a custom hook to the ‘wp_login’ hook that would:- Check if there is a meta data field for the user that just logged in to say they’ve setup their new password
- Redirect them to change their password if they haven’t set it up. Once they have, add a flag for this user
There are probably a lot of plugins that will do this for you. I can’t say if they’re any good but I found a couple that you could try if you’re happy to use those. You could see how they behave with External Login?
- https://wordpress.org/plugins/new-user-password-reset/
- https://github.com/lumpysimon/wp-force-password-change
Let me know your thoughts . . .
π
So the plugin will only allow login with the old password in one condition. If the external server is not available, the plugin will use the local password stored in WordPress to login a user.
As soon as a login is made with the server the password is updated locally in WordPress.
You can tick the box in the settings to disable local login. This will mean if the external database is not accessible it will not attempt to use the local database to login users.
My theory on what could be happening in your case.
- The server was unavailable when you tried to login with the old password so it used the local one (the old password) to validate
- There is a caching issue with your setup?
I would suggest you start by using the same log messages we talked about before to see if you are definitely getting the data back from the server. You can then also check that the new hash is definitely coming back from that query.
That’s brilliant @stikekar!!!
Well done for getting it resolved!
Yeah, there’s a couple of fixes in the pipeline. Started a new job recently so haven’t come round to update but I will continue to support the plugin π
Money received. That was very generous of you and much appreciated.
If you have any more issues don’t hesitate to get back in contact.
Kind regards,
Tom
Forum: Plugins
In reply to: [External Login] Diagnosing why I can’t loginHey @ala7lam,
Really glad you managed to get this resolved π
If you get a minute, I’d be grateful if you could write a review or even buy me a beer.
Thanks,
Tom π