本文整理汇总了PHP中generate_user_password函数的典型用法代码示例。如果您正苦于以下问题:PHP generate_user_password函数的具体用法?PHP generate_user_password怎么用?PHP generate_user_password使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了generate_user_password函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Called before each test object.
*/
public function __construct()
{
$this->ia = elgg_set_ignore_access(TRUE);
parent::__construct();
$this->user = new ElggUser();
$this->user->username = 'test_username_' . rand();
$this->user->email = 'test@test.org';
$this->user->name = 'I am a Test User';
$this->user->access_id = ACCESS_PUBLIC;
$this->user->salt = generate_random_cleartext_password();
$this->user->password = generate_user_password($this->user, "pass123");
$this->user->container_guid = 0;
$this->user->owner_guid = 0;
$this->user->save();
// all __construct() code should come after here
$this->user2 = new ElggUser();
// generating API key
$keypair = create_api_user($CONFIG->site_id);
if ($keypair) {
$this->apikey = new ElggObject();
$this->apikey->subtype = 'api_key';
$this->apikey->access_id = ACCESS_PUBLIC;
$this->apikey->title = "User web services";
$this->apikey->public = $keypair->api_key;
$this->apikey->save();
}
}
示例2: cas_insertUser
/**
* insert user into elgg user table
*
* Get user info from db
* Tries to insert, otherwise return error
*
* @return user
*/
function cas_insertUser($username, $casUser, $config)
{
// $name = $attr['cn'];
// $uname = !empty($attr['textuid']) ? $attr['textuid'] : str_replace(".", "",$username);
// $email = $attr['mail'];
$name = $casUser->name;
$uname = !empty($casUser->username) ? $casUser->username : $username;
$email = $casUser->email;
$password = md5($uname . $email);
$user = new ElggUser();
$user->username = $uname;
$user->email = $email;
$user->name = $name;
$user->access_id = 2;
$user->salt = generate_random_cleartext_password();
// Note salt generated before password!
$user->password = generate_user_password($user, $password);
$user->save();
$guid = $user->guid;
$obj = get_entity($guid);
if (isset($config->casadminuser) && $config->casadminuser == $username) {
if ($obj instanceof ElggUser && $obj->canEdit()) {
$obj->admin = 'yes';
if ($obj->admin) {
system_message(elgg_echo('admin:user:makeadmin:yes'));
} else {
register_error(elgg_echo('admin:user:makeadmin:no'));
}
} else {
register_error(elgg_echo('admin:user:makeadmin:no'));
}
}
return $user;
}
示例3: testUpdateACL
public function testUpdateACL()
{
// another fake user to test with
$user = new ElggUser();
$user->username = 'test_user_' . rand();
$user->email = 'fake_email@fake.com' . rand();
$user->name = 'fake user';
$user->access_id = ACCESS_PUBLIC;
$user->salt = _elgg_generate_password_salt();
$user->password = generate_user_password($user, rand());
$user->owner_guid = 0;
$user->container_guid = 0;
$user->save();
$acl_id = create_access_collection('test acl');
$member_lists = array(array($this->user->guid, $user->guid), array($user->guid), array($this->user->guid), array());
foreach ($member_lists as $members) {
$result = update_access_collection($acl_id, $members);
$this->assertTrue($result);
if ($result) {
$q = "SELECT * FROM {$this->dbPrefix}access_collection_membership\n\t\t\t\t\tWHERE access_collection_id = {$acl_id}";
$data = get_data($q);
if (count($members) == 0) {
$this->assertFalse($data);
} else {
$this->assertEqual(count($members), count($data));
}
foreach ($data as $row) {
$this->assertTrue(in_array($row->user_guid, $members));
}
}
}
delete_access_collection($acl_id);
$user->delete();
}
示例4: elgg_set_user_password
/**
* Set a user's password
*
* @return bool
* @since 1.8.0
* @access private
*/
function elgg_set_user_password()
{
$current_password = get_input('current_password', null, false);
$password = get_input('password', null, false);
$password2 = get_input('password2', null, false);
$user_guid = get_input('guid');
if (!$user_guid) {
$user = elgg_get_logged_in_user_entity();
} else {
$user = get_entity($user_guid);
}
if ($user && $password) {
// let admin user change anyone's password without knowing it except his own.
if (!elgg_is_admin_logged_in() || elgg_is_admin_logged_in() && $user->guid == elgg_get_logged_in_user_guid()) {
$credentials = array('username' => $user->username, 'password' => $current_password);
try {
pam_auth_userpass($credentials);
} catch (LoginException $e) {
register_error(elgg_echo('LoginException:ChangePasswordFailure'));
return false;
}
}
try {
$result = validate_password($password);
} catch (RegistrationException $e) {
register_error($e->getMessage());
return false;
}
if ($result) {
if ($password == $password2) {
$user->salt = _elgg_generate_password_salt();
$user->password = generate_user_password($user, $password);
$user->code = '';
if ($user->guid == elgg_get_logged_in_user_guid() && !empty($_COOKIE['elggperm'])) {
// regenerate remember me code so no other user could
// use it to authenticate later
$code = _elgg_generate_remember_me_token();
$_SESSION['code'] = $code;
$user->code = md5($code);
setcookie("elggperm", $code, time() + 86400 * 30, "/");
}
if ($user->save()) {
system_message(elgg_echo('user:password:success'));
return true;
} else {
register_error(elgg_echo('user:password:fail'));
}
} else {
register_error(elgg_echo('user:password:fail:notsame'));
}
} else {
register_error(elgg_echo('user:password:fail:tooshort'));
}
} else {
// no change
return null;
}
return false;
}
示例5: elgg_set_user_password
/**
* Set a user's password
*
* @return bool
* @since 1.8.0
* @access private
*/
function elgg_set_user_password()
{
$current_password = get_input('current_password');
$password = get_input('password');
$password2 = get_input('password2');
$user_guid = get_input('guid');
if (!$user_guid) {
$user = elgg_get_logged_in_user_entity();
} else {
$user = get_entity($user_guid);
}
if ($user && $password) {
// let admin user change anyone's password without knowing it except his own.
if (!elgg_is_admin_logged_in() || elgg_is_admin_logged_in() && $user->guid == elgg_get_logged_in_user_guid()) {
$credentials = array('username' => $user->username, 'password' => $current_password);
try {
pam_auth_userpass($credentials);
} catch (LoginException $e) {
register_error(elgg_echo('LoginException:ChangePasswordFailure'));
return false;
}
}
try {
$result = validate_password($password);
} catch (RegistrationException $e) {
register_error($e->getMessage());
return false;
}
if ($result) {
if ($password == $password2) {
$user->salt = generate_random_cleartext_password();
// Reset the salt
$user->password = generate_user_password($user, $password);
if ($user->save()) {
system_message(elgg_echo('user:password:success'));
return true;
} else {
register_error(elgg_echo('user:password:fail'));
}
} else {
register_error(elgg_echo('user:password:fail:notsame'));
}
} else {
register_error(elgg_echo('user:password:fail:tooshort'));
}
} else {
// no change
return null;
}
return false;
}
示例6: createUser
/**
* Create a fake user
*
* @return ElggUser
*/
public static function createUser()
{
$user = new ElggUser();
$user->username = 'fake_user_' . rand();
$user->email = 'fake_email@fake.com' . rand();
$user->name = 'fake user ' . rand();
$user->access_id = ACCESS_PUBLIC;
$user->salt = generate_random_cleartext_password();
$user->password = generate_user_password($user, rand());
$user->owner_guid = 0;
$user->container_guid = 0;
$user->save();
return $user;
}
示例7: __construct
/**
* Called before each test object.
*/
public function __construct()
{
parent::__construct();
$this->user = new ElggUser();
$this->user->username = 'fake_user_' . rand();
$this->user->email = 'fake_email@fake.com' . rand();
$this->user->name = 'fake user ' . rand();
$this->user->access_id = ACCESS_PUBLIC;
$this->user->salt = _elgg_generate_password_salt();
$this->user->password = generate_user_password($this->user, rand());
$this->user->owner_guid = 0;
$this->user->container_guid = 0;
$this->user->save();
}
示例8: elgg_set_user_password
/**
* Set a user's password
*
* @return bool
* @since 1.8.0
*/
function elgg_set_user_password()
{
$current_password = get_input('current_password');
$password = get_input('password');
$password2 = get_input('password2');
$user_id = get_input('guid');
if (!$user_id) {
$user = elgg_get_logged_in_user_entity();
} else {
$user = get_entity($user_id);
}
if ($user && $password != "") {
// let admin user change anyone's password without knowing it except his own.
if (!elgg_is_admin_logged_in() || elgg_is_admin_logged_in() && $user->guid == elgg_get_logged_in_user_guid()) {
$credentials = array('username' => $user->username, 'password' => $current_password);
if (!pam_auth_userpass($credentials)) {
register_error(elgg_echo('user:password:fail:incorrect_current_password'));
return false;
}
}
if (strlen($password) >= 4) {
if ($password == $password2) {
$user->salt = generate_random_cleartext_password();
// Reset the salt
$user->password = generate_user_password($user, $password);
if ($user->save()) {
system_message(elgg_echo('user:password:success'));
return true;
} else {
register_error(elgg_echo('user:password:fail'));
}
} else {
register_error(elgg_echo('user:password:fail:notsame'));
}
} else {
register_error(elgg_echo('user:password:fail:tooshort'));
}
} else {
// no change
return null;
}
return false;
}
示例9: pam_auth_userpass
/**
* Hook into the PAM system which accepts a username and password and attempts to authenticate
* it against a known user.
*
* @param array $credentials Associated array of credentials passed to pam_authenticate. This function expects
* 'username' and 'password' (cleartext).
*/
function pam_auth_userpass($credentials = NULL)
{
if (is_array($credentials) && $credentials['username'] && $credentials['password']) {
if ($user = get_user_by_username($credentials['username'])) {
// Let admins log in without validating their email, but normal users must have validated their email or been admin created
if (!$user->admin && !$user->validated && !$user->admin_created) {
return false;
}
// User has been banned, so prevent from logging in
if ($user->isBanned()) {
return false;
}
if ($user->password == generate_user_password($user, $credentials['password'])) {
return true;
} else {
// Password failed, log.
log_login_failure($user->guid);
}
}
}
return false;
}
示例10: register_error
if ($container_guid == '' || $username == '' || $password == '' || $password2 == '' || $email == '' || $name == '') {
register_error("Todos os campos são obrigatórios.");
forward(REFERER);
}
if (strcmp($password, $password2) != 0) {
register_error(elgg_echo('RegistrationException:PasswordMismatch'));
forward(REFERER);
}
try {
$aluno = new Aluno();
$aluno->username = $username;
$aluno->email = $email;
$aluno->name = $name;
$aluno->access_id = ACCESS_PUBLIC;
$aluno->salt = _elgg_generate_password_salt();
$aluno->password = generate_user_password($aluno, $password);
$aluno->owner_guid = 0;
$aluno->container_guid = $container_guid;
$aluno->language = get_current_language();
$guid = $aluno->save();
if ($guid) {
$new_user = get_entity($guid);
elgg_clear_sticky_form('useradd');
$new_user->created_by_guid = elgg_get_logged_in_user_guid();
$subject = elgg_echo('useradd:subject');
$body = elgg_echo('useradd:body', array($name, elgg_get_site_entity()->name, elgg_get_site_entity()->url, $username, $password));
notify_user($new_user->guid, elgg_get_site_entity()->guid, $subject, $body);
system_message(elgg_echo("adduser:ok", array(elgg_get_site_entity()->name)));
} else {
register_error(elgg_echo("adduser:bad"));
}
示例11: register_user
/**
* Registers a user, returning false if the username already exists
*
* @param string $username The username of the new user
* @param string $password The password
* @param string $name The user's display name
* @param string $email Their email address
* @param bool $allow_multiple_emails Allow the same email address to be
* registered multiple times?
* @param int $friend_guid GUID of a user to friend once fully registered
* @param string $invitecode An invite code from a friend
*
* @return int|false The new user's GUID; false on failure
*/
function register_user($username, $password, $name, $email, $allow_multiple_emails = false, $friend_guid = 0, $invitecode = '')
{
// Load the configuration
global $CONFIG;
// no need to trim password.
$username = trim($username);
$name = trim(strip_tags($name));
$email = trim($email);
// A little sanity checking
if (empty($username) || empty($password) || empty($name) || empty($email)) {
return false;
}
// Make sure a user with conflicting details hasn't registered and been disabled
$access_status = access_get_show_hidden_status();
access_show_hidden_entities(true);
if (!validate_email_address($email)) {
throw new RegistrationException(elgg_echo('registration:emailnotvalid'));
}
if (!validate_password($password)) {
throw new RegistrationException(elgg_echo('registration:passwordnotvalid'));
}
if (!validate_username($username)) {
throw new RegistrationException(elgg_echo('registration:usernamenotvalid'));
}
if ($user = get_user_by_username($username)) {
throw new RegistrationException(elgg_echo('registration:userexists'));
}
if (!$allow_multiple_emails && get_user_by_email($email)) {
throw new RegistrationException(elgg_echo('registration:dupeemail'));
}
access_show_hidden_entities($access_status);
// Create user
$user = new ElggUser();
$user->username = $username;
$user->email = $email;
$user->name = $name;
$user->access_id = ACCESS_PUBLIC;
$user->salt = generate_random_cleartext_password();
// Note salt generated before password!
$user->password = generate_user_password($user, $password);
$user->owner_guid = 0;
// Users aren't owned by anyone, even if they are admin created.
$user->container_guid = 0;
// Users aren't contained by anyone, even if they are admin created.
$user->language = get_current_language();
$user->save();
// If $friend_guid has been set, make mutual friends
if ($friend_guid) {
if ($friend_user = get_user($friend_guid)) {
if ($invitecode == generate_invite_code($friend_user->username)) {
$user->addFriend($friend_guid);
$friend_user->addFriend($user->guid);
// @todo Should this be in addFriend?
add_to_river('river/relationship/friend/create', 'friend', $user->getGUID(), $friend_guid);
add_to_river('river/relationship/friend/create', 'friend', $friend_guid, $user->getGUID());
}
}
}
// Turn on email notifications by default
set_user_notification_setting($user->getGUID(), 'email', true);
return $user->getGUID();
}
示例12: pleio_api_change_setting
function pleio_api_change_setting($name = "", $password = "", $language = "", $email = "")
{
$fail = false;
$dirty = false;
$user = elgg_get_logged_in_user_entity();
if ($language && $language != $user->language && array_key_exists($language, get_installed_translations())) {
$user->language = $language;
$dirty = true;
}
if ($email && $email != $user->email) {
if (!is_email_address($email)) {
$fail = elgg_echo('email:save:fail');
} else {
if (!get_user_by_email($email)) {
$user->email = $email;
$dirty = true;
} else {
$fail = elgg_echo('registration:dupeemail');
}
}
}
if ($name && $name != $user->name) {
$name = strip_tags($name);
if (elgg_strlen($name) > 50) {
$fail = elgg_echo('user:name:fail');
} else {
$user->name = $name;
$dirty = true;
}
}
if ($password) {
try {
$result = validate_password($password);
if ($result) {
$user->salt = generate_random_cleartext_password();
$user->password = generate_user_password($user, $password);
$dirty = true;
} else {
$fail = elgg_echo('user:password:fail');
}
} catch (RegistrationException $e) {
$fail = $e->getMessage();
}
}
if ($fail) {
return new ErrorResult($fail);
} else {
if ($dirty) {
if ($user->canEdit() && $user->save()) {
return new SuccessResult("Instellingen opgeslagen");
} else {
return new ErrorResult("Opslaan mislukt");
}
} else {
return new SuccessResult("Instellingen niet gewijzigd");
}
}
return new ErrorResult("Niets gewijzigd");
}
示例13: import_to_stormpath
function import_to_stormpath()
{
$dbprefix = elgg_get_config('dbprefix');
$subject = elgg_get_plugin_setting('import_subject', PLUGIN_ID);
$message = elgg_get_plugin_setting('import_message', PLUGIN_ID);
$site = elgg_get_site_entity();
$site_url = elgg_get_site_url();
if (!$subject || !$message) {
error_log('no subject/message');
return true;
}
if (is_elgg18()) {
$name_id = add_metastring('__stormpath_user');
$value_id = add_metastring(1);
} else {
$name_id = elgg_get_metastring_id('__stormpath_user');
$value_id = elgg_get_metastring_id(1);
}
$options = array('type' => 'user', 'joins' => array("LEFT JOIN {$dbprefix}metadata md ON md.entity_guid = e.guid AND md.name_id = {$name_id}"), 'wheres' => array('md.name_id IS NULL'), 'limit' => false);
$batch = new \ElggBatch('elgg_get_entities', $options);
$batch->setIncrementOffset(false);
foreach ($batch as $user) {
// search stormpath for a matching account
$application = get_application();
$accts = $application->getAccounts(array('email' => $user->email));
$already_exists = false;
foreach ($accts as $a) {
$user->__stormpath_user = $a->href;
error_log('set user ' . $user->username . ': ' . $a->href);
$already_exists = true;
break;
}
if ($already_exists) {
continue;
}
// change it locally
$password = generate_random_cleartext_password();
$user->salt = _elgg_generate_password_salt();
$user->password = generate_user_password($user, $password);
$user->save();
error_log('adding to stormpath ' . $user->email);
$result = add_to_stormpath($user, $password);
if ($result) {
// notify them of the change
// replace tokens in the message
$message_m = str_replace('{{password}}', $password, $message);
$message_m = str_replace('{{name}}', $user->name, $message_m);
$message_m = str_replace('{{username}}', $user->username, $message_m);
$message_m = str_replace('{{email}}', $user->email, $message_m);
$message_m = str_replace('{{forgot_password}}', $site_url . 'forgotpassword', $message_m);
$message_m = str_replace('{{site_email}}', $site->email, $message_m);
$message_m = str_replace('{{site_url}}', $site_url, $message_m);
notify_user($user->guid, $site->guid, $subject, $message_m, null, 'email');
}
}
}
示例14: facebook_connect_login
/**
* Log in a user with facebook.
*/
function facebook_connect_login()
{
global $CONFIG;
elgg_load_library('facebook');
// sanity check
if (!facebook_connect_allow_sign_on_with_facebook()) {
forward();
}
$facebook = facebookservice_api();
$access_token = $facebook->getAccessToken();
// Get User ID
$userID = $facebook->getUser();
if ($userID) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$userID = null;
register_error(elgg_echo('facebook_connect:login:error'));
forward();
}
} else {
system_message(elgg_echo('loginerror'));
forward();
}
// attempt to find user and log them in.
// else, create a new user.
$options = array('type' => 'user', 'plugin_user_setting_name_value_pairs' => array('uid' => $userID, 'access_token' => $access_token), 'plugin_user_setting_name_value_pairs_operator' => 'OR', 'limit' => 0);
$users = elgg_get_entities_from_plugin_user_settings($options);
if (!empty($users)) {
if (count($users) == 1 && login($users[0])) {
system_message(elgg_echo('facebook_connect:login:success'));
elgg_set_plugin_user_setting('access_token', $access_token, $users[0]->guid);
if (empty($users[0]->email)) {
$data = $facebook->api('/me');
$email = $data['email'];
$user = get_entity($users[0]->guid);
$user->email = $email;
$user->save();
}
} else {
system_message(elgg_echo('facebook_connect:login:error'));
}
forward();
} else {
// need facebook account credentials
$data = $facebook->api('/me');
// backward compatibility for stalled-development FBConnect plugin
$user = FALSE;
$facebook_users = elgg_get_entities_from_metadata(array('type' => 'user', 'metadata_name_value_pairs' => array('name' => 'facebook_uid', 'value' => $userID)));
if (is_array($facebook_users) && count($facebook_users) == 1) {
// convert existing account
$user = $facebook_users[0];
login($user);
// remove unused metadata
remove_metadata($user->getGUID(), 'facebook_uid');
remove_metadata($user->getGUID(), 'facebook_controlled_profile');
}
// create new user
if (!$user) {
// check new registration allowed
if (!facebook_connect_allow_new_users_with_facebook()) {
register_error(elgg_echo('registerdisabled'));
forward();
}
$userSave = 0;
$email = $data['email'];
$users = get_user_by_email($email);
if (!$users) {
// Elgg-ify facebook credentials
$username = str_replace(' ', '', strtolower($data['name']));
while (get_user_by_username($username)) {
$username = str_replace(' ', '', strtolower($data['name'])) . '_' . rand(1000, 9999);
}
$permissions = $facebook->api("/me/permissions");
if (array_key_exists('publish_stream', $permissions['data'][0])) {
$postWall = true;
} else {
$postWall = false;
}
$password = generate_random_cleartext_password();
$name = $data['name'];
$user = new ElggUser();
$user->username = $username;
$user->name = $name;
$user->email = $email;
$user->location = $data['locate'];
$user->website = $data['link'];
$user->access_id = ACCESS_PUBLIC;
$user->salt = generate_random_cleartext_password();
$user->password = generate_user_password($user, $password);
$user->owner_guid = 0;
$user->container_guid = 0;
if ($postWall) {
$user->post_wall = true;
}
//.........这里部分代码省略.........
开发者ID:ashwiniravi,项目名称:Elgg-Social-Network-Single-Sign-on-and-Web-Statistics,代码行数:101,代码来源:facebook_connect.php
示例15: register_user
/**
* Registers a user, returning false if the username already exists
*
* @param string $username The username of the new user
* @param string $password The password
* @param string $name The user's display name
* @param string $email The user's email address
* @param bool $allow_multiple_emails Allow the same email address to be
* registered multiple times?
*
* @return int|false The new user's GUID; false on failure
* @throws RegistrationException
*/
function register_user($username, $password, $name, $email, $allow_multiple_emails = false)
{
// no need to trim password.
$username = trim($username);
$name = trim(strip_tags($name));
$email = trim($email);
// A little sanity checking
if (empty($username) || empty($password) || empty($name) || empty($email)) {
return false;
}
// Make sure a user with conflicting details hasn't registered and been disabled
$access_status = access_get_show_hidden_status();
access_show_hidden_entities(true);
if (!validate_email_address($email)) {
throw new RegistrationException(elgg_echo('registration:emailnotvalid'));
}
if (!validate_password($password)) {
throw new RegistrationException(elgg_echo('registration:passwordnotvalid'));
}
if (!validate_username($username)) {
throw new RegistrationException(elgg_echo('registration:usernamenotvalid'));
}
if ($user = get_user_by_username($username)) {
throw new RegistrationException(elgg_echo('registration:userexists'));
}
if (!$allow_multiple_emails && get_user_by_email($email)) {
throw new RegistrationException(elgg_echo('registration:dupeemail'));
}
access_show_hidden_entities($access_status);
// Create user
$user = new ElggUser();
$user->username = $username;
$user->email = $email;
$user->name = $name;
$user->access_id = ACCESS_PUBLIC;
$user->salt = _elgg_generate_password_salt();
$user->password = generate_user_password($user, $password);
$user->owner_guid = 0;
// Users aren't owned by anyone, even if they are admin created.
$user->container_guid = 0;
// Users aren't contained by anyone, even if they are admin created.
$user->language = get_current_language();
if ($user->save() === false) {
return false;
}
// Turn on email notifications by default
set_user_notification_setting($user->getGUID(), 'email', true);
return $user->getGUID();
}