Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

[SOLVED] Protecting a profile with a password?

  • krileon
  • krileon
  • ONLINE
  • Posts: 48474
  • Thanks: 8281
  • Karma: 1443
10 years 11 months ago - 10 years 11 months ago #237720 by krileon
Replied by krileon on topic Protecting a profile with a password?

If I can't change the field's value this way... Then how can I do?

You would need to establish the user object, set a new value, then store it as follows.

Code:
$user = CBuser::getUserDataInstance( (int) '[user_id]' ); $user->set( 'cb_access', 'noaccess' ); $user->store();

The problem with this is it's going to set this to the displayed uses object, which will affect everyone and I do not suggest this approach. You can redirect, throw an error, etc.. to better deny access.

Or could I simply redirect the visitor somewhere else if the condition fails? If I put an echo statement with some JS redirect in it will it be executed?

That would probably be the best approach using cbRedirect( 'URL_HERE' );.

Is there any way I can make the variables to show, just to compare them?

Echo both then configure your code action to output the results.


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.
Last edit: 10 years 11 months ago by krileon.
The following user(s) said Thank You: OldLodgeSkins

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

  • OldLodgeSkins
  • OldLodgeSkins
  • OFFLINE
  • Posts: 119
  • Thanks: 5
  • Karma: 2
  • Add-ons
10 years 11 months ago #237721 by OldLodgeSkins
Replied by OldLodgeSkins on topic Protecting a profile with a password?
Ok, so I'm going with the redirection this is definitely the best solution, however I just can't get those variables to show... I've already tried having echo statements in my PHP code, even with full debug mode they won't show.

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

  • OldLodgeSkins
  • OldLodgeSkins
  • OFFLINE
  • Posts: 119
  • Thanks: 5
  • Karma: 2
  • Add-ons
10 years 11 months ago - 10 years 11 months ago #237722 by OldLodgeSkins
Replied by OldLodgeSkins on topic Protecting a profile with a password?
I managed to have them show in the URL while redirecting...

It seems the MD5 sum rendered by PHP is completely different from the one I have stored in the database using directly MySQL...

Edit: ok I must have made a mistake somewhere while encoding it... When I run select md5("mypassword"); directly from a MySQL prompt it gives me the same value as PHP's. The problem must be in the query I used to encode it... I'll check.
Last edit: 10 years 11 months ago by OldLodgeSkins.

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

  • OldLodgeSkins
  • OldLodgeSkins
  • OFFLINE
  • Posts: 119
  • Thanks: 5
  • Karma: 2
  • Add-ons
10 years 11 months ago #237723 by OldLodgeSkins
Replied by OldLodgeSkins on topic Protecting a profile with a password?
Ok, after manually replacing the value in the database the validation works fine... So it's definitely the way I encoded it. Here's what I did to encode it, maybe you'll see what I don't see?

Type: query
Trigger: onAfterUserUpdate (at that point I'm guessing the field's value has been saved in clear, -> correct? <- so what I'm trying to encode is the right string)
User: user
Code:
UPDATE `#__comprofiler` SET `cb_secretword`= MD5('cb_secretword') WHERE `user_id` = '[user_id]';

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

  • OldLodgeSkins
  • OldLodgeSkins
  • OFFLINE
  • Posts: 119
  • Thanks: 5
  • Karma: 2
  • Add-ons
10 years 11 months ago - 10 years 11 months ago #237724 by OldLodgeSkins
Replied by OldLodgeSkins on topic Protecting a profile with a password?
If I run my query directly in PhpMyAdmin, after editing the field's value manually so it contains the password in clear, I get the exact same result... So the problem has nothing to do with CB it's my query - or could it be the field type? It's a text field (I had to apply the old trick in cb.core.xml because I had too many fields).
Edit: this is weird... I'm looking at the table's structure in PhpMyAdmin and I still have a lot of fields that are of type varchar(255) even though I did apply that change to cb.core.xml successfully... It should have been changed to text... This could be the source of my problem.
Last edit: 10 years 11 months ago by OldLodgeSkins.

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

  • OldLodgeSkins
  • OldLodgeSkins
  • OFFLINE
  • Posts: 119
  • Thanks: 5
  • Karma: 2
  • Add-ons
10 years 11 months ago #237725 by OldLodgeSkins
Replied by OldLodgeSkins on topic Protecting a profile with a password?
Ah got it.. The quotes!!!
Code:
UPDATE `s286o_comprofiler` SET `cb_secretword` = md5( cb_secretword ) WHERE `user_id` = '347'

this worked in PhpMyAdmin I got the right value this time... I still have to test it in my auto action but it should work. I just remove the quotes in md5( cb_secretword )

Thanks for all your help.

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

Moderators: beatnantkrileon
Powered by Kunena Forum