I need plain text password in my plugin

Discussion in 'aMember Pro v.4' started by richard_vencu, Nov 29, 2012.

  1. richard_vencu

    richard_vencu New Member

    Joined:
    Nov 25, 2012
    Messages:
    25
    I want to use encrypted password to store in the remote database of the protected script but at the same time I also need a plain text password to define a MySQL user at the subscription activation time.

    Here is a portion of my plugin:
    PHP:
    public function getPasswordFormat()
        {
            return 
    SavedPassTable::PASSWORD_CRYPT;
        }
     
        public function 
    onSubscriptionAdded(Am_Event $event){
            
    $user $event->getUser();
            
    // 1. Check if user exists in MySQL
            
    if ($this->getPACS()->checkIfUserExists($user->login)) {
                
    // 2. If exists update the password
                
    $this->getPACS()->changePasswordDb($user->login$pass);
            }
            else {
                
    // 3. If not exists create it
                
    $pass $this->getDi()->savedPassTable->findSaved($userSavedPassTable::PASSWORD_PLAIN);
                
    $this->getPACS()->createDbLogin($user->login$pass);
            }
        }
    The code functions except that in my hooked function I end up with an encrypted password not a plain one...
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    replace
    return SavedPassTable::PASSWORD_CRYPT;
    to

    return SavedPassTable::PASSWORD_PLAIN;
    and you will be getting plain-text password.
  3. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    (you will have to crypt it before using for other goals).
    I can recommend to use $user->pass, it is in the Wordpress password format and easy to use.
  4. richard_vencu

    richard_vencu New Member

    Joined:
    Nov 25, 2012
    Messages:
    25
    So I got the plain password in my remote DB table by using this script
    PHP:
        public function getPasswordFormat()
        {
            return 
    SavedPassTable::PASSWORD_PLAIN;
        }
     
        public function 
    onSubscriptionAdded(Am_Event $event){
            
    $user $event->getUser();
            
    $pass $this->getDi()->savedPassTable->findSaved($userSavedPassTable::PASSWORD_PLAIN);
            
    //$pass = $user->pass;
            // 1. Check if user exists in MySQL
            
    if ($this->getPACS()->checkIfUserExists($user->login)) {
                
    // 2. If exists update the password
                
    $this->getPACS()->changePasswordDb($user->login$pass);
            }
            else {
                
    // 3. If not exists create it
                
    $this->getPACS()->createDbLogin($user->login$pass);
            }
        }
    But during the event when I try to access the plain password in the second function I end up with something scrambled. I understand the $user->pass in WordPress format is not plain text either. Do I have any chance to use a plain text password except for transitory times when the user actually submits it (at registration or login)?

    Or maybe I am wrong somewhere?
  5. richard_vencu

    richard_vencu New Member

    Joined:
    Nov 25, 2012
    Messages:
    25
    Apparently this is solving my issue
    PHP:
    $pass $this->getDi()->savedPassTable->findSaved($userSavedPassTable::PASSWORD_PLAIN)->pass;

Share This Page