本文整理汇总了PHP中JUserHelper::getCryptedPassword方法的典型用法代码示例。如果您正苦于以下问题:PHP JUserHelper::getCryptedPassword方法的具体用法?PHP JUserHelper::getCryptedPassword怎么用?PHP JUserHelper::getCryptedPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JUserHelper
的用法示例。
在下文中一共展示了JUserHelper::getCryptedPassword方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action
public function action($request)
{
$db = JFactory::getDBO();
$set = array();
if ($this->settings['activate']) {
$set[] = '`block` = \'0\'';
$set[] = '`activation` = \'\'';
}
$username = $this->getUsername($request);
if (!empty($username)) {
$set[] = '`username` = \'' . $username . '\'';
}
if (!empty($this->settings['password'])) {
$pw = AECToolbox::rewriteEngineRQ($this->settings['password'], $request);
jimport('joomla.user.helper');
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($pw, $salt);
$password = $crypt . ':' . $salt;
$set[] = '`password` = \'' . $password . '\'';
}
if (!empty($set)) {
$query = 'UPDATE #__users';
$query .= ' SET ' . implode(', ', $set);
$query .= ' WHERE `id` = \'' . (int) $request->metaUser->userid . '\'';
$db->setQuery($query);
$db->query() or die($db->stderr());
$userid = $request->metaUser->userid;
// Reloading metaUser object for other MIs
$request->metaUser = new metaUser($userid);
}
if (!empty($this->settings['set_fields'])) {
$this->setFields($request);
}
}
示例2: ajaxSaveRow
function ajaxSaveRow()
{
$user = JFactory::getUser();
$id = $user->get('id');
jimport('joomla.mail.helper');
jimport('joomla.user.helper');
global $mainframe;
$db =& JFactory::getDBO();
$varolan = JRequest::getVar('varolan');
$yeni = JRequest::getVar('yeni');
$sql = "select password from jos_users where id={$id}";
$liste = mysql_fetch_array(mysql_query($sql));
$parts = explode(":", $liste[password]);
$crypt = $parts[0];
$salt = @$parts[1];
$testcrypt = JUserHelper::getCryptedPassword($varolan, $salt);
if ($crypt == $testcrypt) {
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($yeni, $salt);
$password = $crypt . ':' . $salt;
$query = 'UPDATE #__users' . ' SET `password` = "' . $password . '"' . ' WHERE id = ' . (int) $id . ' AND block = 0';
$db->setQuery($query);
$db->query();
echo "<p align=center>Şifreniz başarıyla değiştirildi.</p>";
} else {
echo "<p align=center>Geçerli şifreniz yanlış.</p><p align=center><a href='index.php?option=com_user&view=changepass'>Yeniden deneyiniz</a></p>";
}
}
示例3: addTempUser
public function addTempUser($data)
{
$db =& $this->getDBO();
//get current session id.
$mySess =& JFactory::getSession();
$token = $mySess->get('JS_REG_TOKEN', '');
$nowDate = JFactory::getDate();
$nowDate = $nowDate->toMysql();
// Combine firsname and last name as full name
if (empty($data['jsname'])) {
$data['jsname'] = $data['jsfirstname'] . ' ' . $data['jslastname'];
}
$obj = new stdClass();
$obj->name = $data['jsname'];
$obj->firstname = isset($data['jsfirstname']) ? $data['jsfirstname'] : '';
$obj->lastname = isset($data['jslastname']) ? $data['jslastname'] : '';
$obj->token = $token;
$obj->username = $data['jsusername'];
$obj->email = $data['jsemail'];
$obj->password = $data['jspassword'];
$obj->created = $nowDate;
$obj->ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
// no clear text password store in db
jimport('joomla.user.helper');
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($obj->password, $salt);
$obj->password = $crypt . ':' . $salt;
$db->insertObject('#__community_register', $obj);
if ($db->getErrorNum()) {
JError::raiseError(500, $db->stderr());
}
$this->return_value[__FUNCTION__] = true;
return $this;
}
示例4: generateToken
/**
* Generate token here to standardize the token generation
* @condition if the userId is provided it will be assign to the user directly
* @see assignToken()
* @return String generated token
*/
public function generateToken()
{
$salt = JUserHelper::genRandomPassword(20);
$crypt = JUserHelper::getCryptedPassword(rand(), $salt);
$token = $crypt . ':' . $salt;
return $token;
}
示例5: onAuthenticate
function onAuthenticate($credentials, $options, &$response)
{
jimport('joomla.user.helper');
if (empty($credentials['password'])) {
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = 'Empty password not allowed';
return false;
}
$db =& JFactory::getDBO();
$sql = 'SELECT `id`, `password`, `gid` FROM `#__users` WHERE payroll=' . $db->Quote($credentials['username']);
$db->setQuery($sql);
$result = $db->loadObject();
if ($result) {
$parts = explode(':', $result->password);
$crypt = $parts[0];
$salt = @$parts[1];
$testcrypt = JUserHelper::getCryptedPassword($credentials['password'], $salt);
if ($crypt == $testcrypt) {
$user = JUser::getInstance($result->id);
// Bring this in line with the rest of the system
$response->username = $user->username;
$response->email = $user->email;
$response->fullname = $user->name;
$response->status = JAUTHENTICATE_STATUS_SUCCESS;
$response->error_message = '';
} else {
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = 'Invalid password';
}
} else {
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = 'User does not exist';
}
}
示例6: simple_registration
function simple_registration($username, $password, $name, $email, $defaultUserGroups = array(2))
{
//Default group 2=registered
$result = array('error', 'message');
$usersConfig =& JComponentHelper::getParams('com_users');
if ($usersConfig->get('allowUserRegistration') == '1') {
//PASSWORD
$salt = JUserHelper::genRandomPassword(32);
$password_clear = $password;
$crypted = JUserHelper::getCryptedPassword($password_clear, $salt);
$password = $crypted . ':' . $salt;
//set
$instance = JUser::getInstance();
$instance->set('id', 0);
$instance->set('name', $name);
$instance->set('username', $username);
$instance->set('password', $password);
$instance->set('password_clear', $password_clear);
$instance->set('email', $email);
$instance->set('groups', $defaultUserGroups);
if (!$instance->save()) {
//resultat
$result['error'] = true;
$result['message'] = 'bad data';
} else {
$result['error'] = false;
$result['message'] = 'success';
}
} else {
$result['error'] = true;
$result['message'] = 'no allow user registration';
}
return $result;
}
示例7: authenticate
private function authenticate($username, $password = null, $valid = 86400)
{
// Get a database object
$db = JFactory::getDbo();
// Look for any tokens for this user
$db->setQuery($db->getQuery(true)->select('*')->from('#__rvs_user_tokens')->where('uid=' . $db->q($result->id)));
$obj = $db->loadObject();
// If there is already a valid token, just return that, otherwise try to create one
if ($obj->valid > JDate::getInstance()->toUnix()) {
return $obj->token;
} else {
$db->setQuery($db->getQuery(true)->select('id, password')->from('#__users')->where('username=' . $db->q($username)));
$result = $db->loadObject();
$parts = explode(':', $result->password);
$crypt = $parts[0];
$salt = @$parts[1];
$testcrypt = JUserHelper::getCryptedPassword($password, $salt);
if ($crypt == $testcrypt) {
// Authentication successful, create a token and populate the table
$obj = new stdClass();
$obj->uid = $result->id;
$obj->token = md5(rand() . $salt);
$obj->valid = JDate::getInstance()->toUnix() + $valid;
$db->setQuery($db->getQuery(true)->select('uid')->from('#__rvs_user_tokens')->where('uid=' . $db->q($obj->uid)));
if ($db->loadResult()) {
$db->updateObject('#__rvs_user_tokens', $obj, 'uid');
} else {
$db->insertObject('#__rvs_user_tokens', $obj, 'uid');
}
return $obj->token;
}
}
return null;
}
示例8: changepassword
function changepassword()
{
$mainframe = JFactory::getApplication();
$return = JRequest::getVar('return', 0);
$return = base64_decode($return);
$user_data = $_POST;
if ($user_data['password'] == $user_data['password2']) {
$user = JFactory::getUser();
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword(JString::trim($user_data['password']), $salt);
$password = $crypt . ':' . $salt;
$user->set('password', $password);
if ($user->save()) {
$mainframe->enqueueMessage(JText::_('Successfully saved'), 'message');
}
} else {
JError::raiseWarning('', JText::_(' Passwords do not match. Please re-enter password.'));
}
$config = JBFactory::getConfig();
if ($return) {
$this->setRedirect($return);
} else {
$this->setRedirect('index.php?option=com_bookpro&view=account&form=password&Itemid=' . JRequest::getVar('Itemid'));
}
}
示例9: onUserAfterLogin
/**
* Password is saved to Joomla DB after succesful authentication
*
* @access public
* @return boolean
* @since 1.5
*/
function onUserAfterLogin()
{
/* po uspesnem prihlaseni ulozime heslo */
if (isset($_POST["password"]) && $_POST["password"] != "") {
// misto $_POST["password"] by melo byt
//$jinput = JFactory::getApplication()->input;
//$password = $jinput->get('password', '', 'STRING');
// http://stackoverflow.com/questions/2727043/using-php-to-create-a-joomla-user-password
jimport('joomla.user.helper');
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($_POST["password"], $salt);
$password = $crypt . ':' . $salt;
// Get a database object
$user = JFactory::getUser();
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$fields = array($db->quoteName('password') . ' = "' . $password . '"');
$conditions = array($db->quoteName('username') . ' = "' . $user->username . '"');
$query->update($db->quoteName('#__users'))->set($fields)->where($conditions);
$db->setQuery($query);
$result = $db->execute();
return $result;
}
return false;
}
示例10: hashPassword
function hashPassword($password)
{
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_LIBRARIES . '/joomla/user/helper.php';
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($password, $salt);
return "{$crypt}:{$salt}";
}
示例11: storeDatabaseFormat
/**
* Manupulates posted form data for insertion into database
*
* @param mixed $val this elements posted form data
* @param array $data posted form data
*
* @return mixed
*/
public function storeDatabaseFormat($val, $data)
{
jimport('joomla.user.helper');
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($val, $salt);
$val = $crypt . ':' . $salt;
return $val;
}
示例12: onUserAuthenticate
/**
* This method should handle any authentication and report back to the subject
*/
function onUserAuthenticate($credentials, $options, &$response)
{
jimport('joomla.user.helper');
jimport('joomla.version');
$version = new JVersion();
$version = explode('.', $version->getShortVersion());
if ($version[0] == 3) {
$success = JAuthentication::STATUS_SUCCESS;
$failure = JAuthentication::STATUS_FAILURE;
} else {
$success = JAUTHENTICATE_STATUS_SUCCESS;
$failure = JAUTHENTICATE_STATUS_FAILURE;
}
$response->type = 'Joomla';
// Joomla does not like blank passwords
if (empty($credentials['password'])) {
$response->status = $failure;
$response->error_message = JText::_('JGLOBAL_AUTH_EMPTY_PASS_NOT_ALLOWED');
return false;
}
// Initialise variables.
$conditions = '';
// Get a database object
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id, password');
$query->from('#__users');
$query->where('email=' . $db->Quote($credentials['username']));
$db->setQuery($query);
$result = $db->loadObject();
if ($result) {
$parts = explode(':', $result->password);
$crypt = $parts[0];
$salt = @$parts[1];
$testcrypt = JUserHelper::getCryptedPassword($credentials['password'], $salt);
if ($crypt == $testcrypt) {
$user = JUser::getInstance($result->id);
// Bring this in line with the rest of the system
$response->username = $user->username;
$response->email = $user->email;
$response->fullname = $user->name;
if (JFactory::getApplication()->isAdmin()) {
$response->language = $user->getParam('admin_language');
} else {
$response->language = $user->getParam('language');
}
$response->status = $success;
$response->error_message = '';
} else {
$response->status = $failure;
$response->error_message = JText::_('JGLOBAL_AUTH_INVALID_PASS');
}
} else {
$response->status = $failure;
$response->error_message = JText::_('JGLOBAL_AUTH_NO_USER');
}
}
示例13: generatePassword
public static function generatePassword($text, $is_cripted = false)
{
$password = $text;
if ($is_cripted == false) {
return $password;
}
jimport('joomla.user.helper');
$salt = JUserHelper::genRandomPassword(8);
$crypt = JUserHelper::getCryptedPassword($password, $salt);
$password = $crypt . ":" . $salt;
return $password;
}
示例14: post
/**
* Function post for create user record.
*
* @return void
*/
public function post()
{
$error_messages = array();
$fieldname = array();
$response = null;
$validated = true;
$userid = null;
$data = array();
$app = JFactory::getApplication();
$data['username'] = $app->input->get('username', '', 'STRING');
$data['password'] = $app->input->get('password', '', 'STRING');
$data['name'] = $app->input->get('name', '', 'STRING');
$data['email'] = $app->input->get('email', '', 'STRING');
global $message;
jimport('joomla.user.helper');
$authorize = JFactory::getACL();
$user = clone JFactory::getUser();
$user->set('username', $data['username']);
$user->set('password', $data['password']);
$user->set('name', $data['name']);
$user->set('email', $data['email']);
// Password encryption
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($user->password, $salt);
$user->password = "{$crypt}:{$salt}";
// User group/type
$user->set('id', '');
$user->set('usertype', 'Registered');
if (JVERSION >= '1.6.0') {
$userConfig = JComponentHelper::getParams('com_users');
// Default to Registered.
$defaultUserGroup = $userConfig->get('new_usertype', 2);
$user->set('groups', array($defaultUserGroup));
} else {
$user->set('gid', $authorize->get_group_id('', 'Registered', 'ARO'));
}
$date =& JFactory::getDate();
$user->set('registerDate', $date->toSql());
// True on success, false otherwise
if (!$user->save()) {
$message = "not created because of " . $user->getError();
return false;
} else {
$message = "created of username-" . $user->username . " and send mail of details please check";
}
// #$this->plugin->setResponse($user->id);
$userid = $user->id;
// Result message
$result = array('user id ' => $userid, 'message' => $message);
$result = $userid ? $result : $message;
$this->plugin->setResponse($result);
}
示例15: generateToken
/**
* Generate token here to standardize the token generation
* @condition if the user_id is provided it will be assign to the user directly
* @see assignToken()
* @return String generated token
*/
public function generateToken($user_id = null)
{
$salt = JUserHelper::genRandomPassword(50);
$crypt = JUserHelper::getCryptedPassword($user_id, $salt);
$token = $crypt . ':' . $salt;
if ($user_id != NULL) {
if ($this->assignToken($user_id, $token)) {
return true;
} else {
return false;
}
} else {
return $token;
}
}