/** * Random token generator */ public static function get_token($length) { $token = ""; $codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $codeAlphabet .= "abcdefghijklmnopqrstuvwxyz"; $codeAlphabet .= "0123456789"; for ($i = 0; $i < $length; $i++) { $token .= $codeAlphabet[SecurityAPI::crypto_rand_secure(0, strlen($codeAlphabet))]; } return $token; }
public static function do_reset_content_user_password($user_name) { // 1. Verify that the user name exists in the system $user_party_data = EntityAPI::get_by_field('party', 'user_name', $user_name); if (!isset($user_party_data['id'])) { return array('has_errors' => true, 'message' => "Sorry the username you provided is not registered"); } // 2. Load the person associated with the party $user_person_data = EntityAPI::get_by_field('person', 'person_party', $user_party_data['id']); if (!isset($user_person_data['id'])) { return array('has_errors' => true, 'message' => "Sorry could not load the data for specified individual"); } // Build the content user data $content_user_data = array('user_pass' => SecurityAPI::generate_password(), 'last_name' => $user_person_data['last_name'], 'first_name' => $user_person_data['first_name'], 'user_login' => $user_party_data['user_name']); MailAPI::do_send_user_password_email($content_user_data, array()); return array('has_errors' => false, 'content_user' => $content_user_data); }