Difference between revisions of "How to store plain text passwords for users"

From aMember Pro Documentation
Jump to: navigation, search
Line 3: Line 3:
 
1. Create field in aMember CP -> Add fields-> New field:  
 
1. Create field in aMember CP -> Add fields-> New field:  
  
Field Name: '''plain_password'''
+
*Field Name: '''plain_password'''
 
+
*Field Title: '''Plain Text Password'''
Field Title: '''Plain Text Password'''
+
*Field Type: '''SQL'''
 
+
*SQL Field Type: '''String'''
Field Type: '''SQL'''
+
 
+
SQL Field Type: '''String'''
+
 
+
  
 
2. Add this code to [[site.php file]]:
 
2. Add this code to [[site.php file]]:

Revision as of 03:40, 9 August 2013

IMPORTANT NOTE We do not recommend to store plain text passwords. Use this tutorial at your own risk.

1. Create field in aMember CP -> Add fields-> New field:

  • Field Name: plain_password
  • Field Title: Plain Text Password
  • Field Type: SQL
  • SQL Field Type: String

2. Add this code to site.php file:

<?php
 
Am_Di::getInstance()->hook->add(Am_Event::SET_PASSWORD, 'savePlainTextPassword');
 
function savePlainTextPassword(Am_Event_SetPassword $event){
    $pass = $event->getPassword();
    $user = $event->getUser();
    if($pass){
        $user->updateQuick('plain_password', $pass);
    }
}

Each time when user's password will be updated aMember will copy it to plain_password field. Then you can use %user.plain_password% placeholder in all emails templates when %user% placeholder is available.