Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Set username/password via cron?
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Set username/password via cron?

YmpkerYmpker Member

Hello,
As I am running a website monitoring script for my free shared hosting where I want to have a demo account that is available for everyone, I'd like to setup a cron that sets the username/password of the public user to demo/demo every 15 minutes. The reason for this is some folks having the time of their life changing demo account credentials. I want to prevent this by resetting them every 15 mins. How would I go about this?

Comments

  • Awmusic12635Awmusic12635 Member, Host Rep

    Is this for cPanel? I believe cPanel has a demo mode itself.

    Thanked by 1MrEd
  • YmpkerYmpker Member

    @Awmusic12635 said:
    Is this for cPanel? I believe cPanel has a demo mode itself.

    No for phpservermonitor (monitor.ympker.net). So Id need to somehow overwrite the respective value in the existing mysqldb where username/pw of the certain user is defined.

  • Awmusic12635Awmusic12635 Member, Host Rep

    In that case I assume you could just write a quick and easy php script to connect to mysql and run the sql command to do an update and then have that script called via cron.

    Thanked by 1Ympker
  • YmpkerYmpker Member

    @Awmusic12635 said:
    In that case I assume you could just write a quick and easy php script to connect to mysql and run the sql command to do an update and then have that script called via cron.

    Good idea :P I might just attempt to do that^^

  • jarjar Patron Provider, Top Host, Veteran
    edited June 2017
    import pymysql.cursors
    import pymysql
    
    sqluser="username"
    sqlpass="password"
    
    def resetpw():
        connection = pymysql.connect('localhost', 'root', 'mysqlpassword', 'databasename')
        cursor = connection.cursor()
        query = ("UPDATE users SET password=PASSWORD(%s) where username=%s;")
        cursor.execute(query, (sqluser, sqlpass))
    
    resetpw()
    

    Off the top of my head, may need some adjustment. Potential typos. Python obviously. Requires pymysql. Assumes password function in MySQL is the proper format for the password, may very well not be.

    You could also just break the ability to change the credentials in a demo app.

    Thanked by 2Ympker JackH
  • r0xzr0xz Member

    just disable/remove the change password function!

  • cron what, cron linux?

    mysql -uuser -ppass -hlocalhost database -E 'update blabla'

    Not very safe to add PW but well, script will have it anyway also. Root might not even need one either for MySQL.

  • JustAMacUserJustAMacUser Member
    edited June 2017

    William said: Not very safe to add PW but well, script will have it anyway [...]

    You can just create a ~/.my.cnf file with the credentials then the password won't appear in any process lists.

  • nunimnunim Member

    @Ympker said:

    @Awmusic12635 said:
    In that case I assume you could just write a quick and easy php script to connect to mysql and run the sql command to do an update and then have that script called via cron.

    Good idea :P I might just attempt to do that^^

    That's how you need to do it as god knows what will be added/injected into the DB and/or files. If you're doing a demo it needs to reinstall files/DB completely every X interval. Easy enough to setup a cronjob to run your installer script.

  • YmpkerYmpker Member

    @William said:
    cron what, cron linux?

    mysql -uuser -ppass -hlocalhost database -E 'update blabla'

    Not very safe to add PW but well, script will have it anyway also. Root might not even need one either for MySQL.

    Linux :)

  • As monitor script runs itself every x time. You can just add a small code to update password when checking uptime. Update time would be much less than 15m and processing would also be less

    Thanked by 1Ympker
  • YmpkerYmpker Member
    edited June 2017

    Currently trying to add a bashscript to cron but @jetchirag idea is also good :)

    !/bin/bash

    mysql -u root -pmyrootpw

    <<RESETPW_QUERRY

    SET PASSWORD FOR 'uptime'@'localhost' = newpw

    RESETPW_QUERRY

  • @Ympker said:
    Currently trying to add a bashscript to cron but @jetchirag idea is also good :)

    !/bin/bash

    mysql -u root -pmyrootpw

    <<RESETPW_QUERRY

    SET PASSWORD FOR 'uptime'@'localhost' = newpw

    RESETPW_QUERRY

    Or why not just disable password update function?

  • YmpkerYmpker Member

    @jetchirag said:

    @Ympker said:
    Currently trying to add a bashscript to cron but @jetchirag idea is also good :)

    !/bin/bash

    mysql -u root -pmyrootpw

    <<RESETPW_QUERRY

    SET PASSWORD FOR 'uptime'@'localhost' = newpw

    RESETPW_QUERRY

    Or why not just disable password update function?

    I didnt look at the files yet but that would be an option, too^^

  • jetchiragjetchirag Member
    edited June 2017

    @Ympker said:

    @jetchirag said:

    @Ympker said:
    Currently trying to add a bashscript to cron but @jetchirag idea is also good :)

    !/bin/bash

    mysql -u root -pmyrootpw

    <<RESETPW_QUERRY

    SET PASSWORD FOR 'uptime'@'localhost' = newpw

    RESETPW_QUERRY

    Or why not just disable password update function?

    I didnt look at the files yet but that would be an option, too^^

    No problem but I did a look at files. If you want to go this way.

    on file: src/psm/Service/User.php

    remove line 398-400 but if there's an uupdate, you'll have to do it again (not a big task tbh).

    $query_update = $this->db_connection->prepare('UPDATE '.PSM_DB_PREFIX.'users SET password = :user_password_hash,
                                                           password_reset_hash = NULL, password_reset_timestamp = NULL
                                                           WHERE user_id = :user_id');
    
    Thanked by 1Ympker
  • YmpkerYmpker Member

    @jetchirag said:

    @Ympker said:

    @jetchirag said:

    @Ympker said:
    Currently trying to add a bashscript to cron but @jetchirag idea is also good :)

    !/bin/bash

    mysql -u root -pmyrootpw

    <<RESETPW_QUERRY

    SET PASSWORD FOR 'uptime'@'localhost' = newpw

    RESETPW_QUERRY

    Or why not just disable password update function?

    I didnt look at the files yet but that would be an option, too^^

    No problem but I did a look at files. If you want to go this way.

    on file: src/psm/Service/User.php

    remove line 398-400 but if there's an application , you'll have to do it again (not a big task tbh).

    $query_update = $this->db_connection->prepare('UPDATE '.PSM_DB_PREFIX.'users SET password = :user_password_hash,
                                                         password_reset_hash = NULL, password_reset_timestamp = NULL
                                                         WHERE user_id = :user_id');
    

    It works :P Thanks! Ive been a bit lazy tbh but you've done a well job there mate!
    Speaking of which if you have a BTC wallet I can send you some so you can go buy yourself a cup of coffee^^ You've earned it :)

  • jetchiragjetchirag Member
    edited June 2017

    @Ympker said:

    @jetchirag said:

    @Ympker said:

    @jetchirag said:

    @Ympker said:
    Currently trying to add a bashscript to cron but @jetchirag idea is also good :)

    !/bin/bash

    mysql -u root -pmyrootpw

    <<RESETPW_QUERRY

    SET PASSWORD FOR 'uptime'@'localhost' = newpw

    RESETPW_QUERRY

    Or why not just disable password update function?

    I didnt look at the files yet but that would be an option, too^^

    No problem but I did a look at files. If you want to go this way.

    on file: src/psm/Service/User.php

    remove line 398-400 but if there's an application , you'll have to do it again (not a big task tbh).

    $query_update = $this->db_connection->prepare('UPDATE '.PSM_DB_PREFIX.'users SET password = :user_password_hash,
                                                           password_reset_hash = NULL, password_reset_timestamp = NULL
                                                           WHERE user_id = :user_id');
    

    It works :P Thanks! Ive been a bit lazy tbh but you've done a well job there mate!
    Speaking of which if you have a BTC wallet I can send you some so you can go buy yourself a cup of coffee^^ You've earned it :)

    Thanks, nevermind :P

    P.S. I don't really have a BTC wallet. Never used it tbh :P

    Thanked by 1Ympker
Sign In or Register to comment.