本文整理汇总了PHP中generate_random_cleartext_password函数的典型用法代码示例。如果您正苦于以下问题:PHP generate_random_cleartext_password函数的具体用法?PHP generate_random_cleartext_password怎么用?PHP generate_random_cleartext_password使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了generate_random_cleartext_password函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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 = generate_random_cleartext_password();
$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();
}
示例3: __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();
}
}
示例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');
$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;
}
示例5: 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;
}
示例6: __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 = generate_random_cleartext_password();
$this->user->password = generate_user_password($this->user, rand());
$this->user->owner_guid = 0;
$this->user->container_guid = 0;
$this->user->save();
}
示例7: post
/**
* {@inheritdoc}
*/
public function post(ParameterBag $params)
{
if (!elgg_get_config('allow_registration') && !elgg_trigger_plugin_hook('allow_registration', 'graph')) {
throw new \RegistrationException(elgg_echo('registerdisabled'), 403);
}
$email = $params->email;
$email_parts = explode('@', $params->email);
$username = $params->username ?: Registration::generateUsername();
$password = $params->password ?: generate_random_cleartext_password();
$name = $params->name ?: array_shift($email_parts);
$guid = register_user($username, $password, $name, $email);
if (!$guid) {
throw new RegistrationException(elgg_echo('registerbad'));
}
$new_user = get_entity($guid);
$new_user->language = $params->language;
$hook_params = array('user' => $new_user, 'password' => $password, 'friend_guid' => $this->graph->get($params->friend_uid)->guid, 'invitecode' => $params->invitecode);
if (!elgg_trigger_plugin_hook('validate_registration', 'graph', null, true)) {
// disable uservalidationbyemail
elgg_unregister_plugin_hook_handler('register', 'user', 'uservalidationbyemail_disable_new_user');
}
$ia = elgg_set_ignore_access(true);
$params->guid = $new_user->guid;
if (!isset($params->access_id)) {
$params->access_id = ACCESS_PRIVATE;
}
$ctrl = new UserProfile($this->request, $this->graph);
$ctrl->put($params);
elgg_set_ignore_access($ia);
$return = array('nodes' => array($new_user));
if (!elgg_trigger_plugin_hook('register', 'user', $hook_params, true)) {
$ia = elgg_set_ignore_access(true);
$new_user->delete();
elgg_set_ignore_access($ia);
throw new RegistrationException(elgg_echo('registerbad'));
}
if ($params->notify) {
$subject = elgg_echo('useradd:subject', array(), $new_user->language);
$body = elgg_echo('useradd:body', array($name, elgg_get_site_entity()->name, elgg_get_site_entity()->url, $username, $password), $new_user->language);
notify_user($new_user->guid, elgg_get_site_entity()->guid, $subject, $body);
}
return $return;
}
示例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: handle
/**
* {@inheritdoc}
*/
protected function handle()
{
$admin = $this->option('admin');
$notify = $this->option('notify');
$email = $this->ask('Enter account email: ');
list($username, ) = explode('@', $email, 2);
$username = $this->ask("Enter account username [{$username}]: ", $username);
$password = $this->ask('Enter account password (leave empty to autegenerate): ', null, true, false);
if (empty($password)) {
$password = generate_random_cleartext_password();
}
$name = $this->ask("Enter account display name [{$username}]: ", $username);
$guid = register_user($username, $password, $name, $email);
$user = get_entity($guid);
$user->admin_created = true;
elgg_set_user_validation_status($user->guid, true, 'cli');
$params = ['user' => $user, 'password' => $password];
if (!elgg_trigger_plugin_hook('register', 'user', $params, TRUE)) {
$ia = elgg_set_ignore_access(true);
$user->delete();
elgg_set_ignore_access($ia);
throw new RegistrationException(elgg_echo('registerbad'));
}
if ($admin) {
$ia = elgg_set_ignore_access(true);
$user->makeAdmin();
elgg_set_ignore_access($ia);
}
if ($notify) {
$subject = elgg_echo('useradd:subject', array(), $user->language);
$body = elgg_echo('useradd:body', array($name, elgg_get_site_entity()->name, elgg_get_site_entity()->url, $username, $password), $user->language);
notify_user($user->guid, elgg_get_site_entity()->guid, $subject, $body, ['password' => $password]);
}
if ($user->isAdmin()) {
system_message("New admin user has been registered [guid: {$user->guid}]");
} else {
system_message("New user has been registered [guid: {$user->guid}]");
}
}
示例10: simplesaml_register_user
/**
* Register a user in Elgg based on information provided by the Service Provider (SP).
*
* @param string $name the (display)name of the new user
* @param string $email the email address of the user
* @param string $saml_source the name of the SP this information came from
* @param bool $validate do we need to validate the email address of this new users
* @param string $username the username provided by the SP (optional)
*
* @return false|ElggUser
*/
function simplesaml_register_user($name, $email, $saml_source, $validate = false, $username = '')
{
if (empty($name) || empty($email) || empty($saml_source)) {
return false;
}
// check which username to use
if (!empty($username)) {
// make sure the username is unique
$username = simplesaml_generate_unique_username($username);
} else {
// create a username from email
$username = simplesaml_generate_username_from_email($email);
}
if (empty($username)) {
register_error(elgg_echo("registration:usernamenotvalid"));
return false;
}
// generate a random password
$password = generate_random_cleartext_password();
try {
$user_guid = register_user($username, $password, $name, $email);
if (empty($user_guid)) {
return false;
}
$new_user = get_user($user_guid);
if (!$validate) {
// no need for extra validation. We trust this user
elgg_set_user_validation_status($new_user->getGUID(), true, 'simplesaml');
}
$params = ['user' => $new_user, 'password' => $password, 'friend_guid' => null, 'invitecode' => null];
if (!elgg_trigger_plugin_hook('register', 'user', $params, true)) {
register_error(elgg_echo('registerbad'));
} else {
return $new_user;
}
} catch (Exception $e) {
register_error($e->getMessage());
}
return false;
}
示例11: twitter_api_create_user
/**
* Create a new user from Twitter information
*
* @param object $twitter Twitter OAuth response
* @return ElggUser
*/
function twitter_api_create_user($twitter)
{
// check new registration allowed
if (!twitter_api_allow_new_users_with_twitter()) {
register_error(elgg_echo('registerdisabled'));
forward();
}
// Elgg-ify Twitter credentials
$username = $twitter->screen_name;
while (get_user_by_username($username)) {
// @todo I guess we just hope this is good enough
$username = $twitter->screen_name . '_' . rand(1000, 9999);
}
$password = generate_random_cleartext_password();
$name = $twitter->name;
$user = new ElggUser();
$user->username = $username;
$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;
$user->container_guid = 0;
if (!$user->save()) {
register_error(elgg_echo('registerbad'));
forward();
}
return $user;
}
示例12: cas_insertUser
/**
* Insert user into elgg user table using info from ldap
* Tries to insert, otherwise returns error
*
* @return user or error (false?)
*/
function cas_insertUser($username, $ldap_attributes, $config)
{
// name is 'cn' in ldap
$name = $ldap_attributes['cn'];
// remove periods from ldap username
// ex. anthony.hopkins -> anthonyhopkins
$uname = !empty($ldap_attributes['textUid']) ? $ldap_attributes['textUid'] : str_replace(".", "", $username);
$email = $ldap_attributes['mail'];
$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!
// cas users don't need password stored locally
// so create an invalid password
// a real password can be saved at a later time if they become a local user
$user->password = md5(time());
//generate_user_password($user, $password);
// returns guid or false
$guid = $user->save();
if (!$guid) {
return false;
}
$obj = get_entity($guid);
if (isset($config->casadminuser) && $config->casadminuser == $uname) {
if ($obj instanceof \ElggUser) {
//set context for permissions check
elgg_push_context('au_cas_auth_make_admin');
if (make_user_admin($guid)) {
system_message(elgg_echo('admin:user:makeadmin:yes'));
} else {
register_error(elgg_echo('admin:user:makeadmin:no'));
}
// set context back
elgg_pop_context();
} else {
register_error(elgg_echo('admin:user:makeadmin:no'));
}
}
return $user;
}
示例13: 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();
}
示例14: elgg_tokeninput_get_secret
/**
* Returns a secret key to sign ajax requests
* @return string
*/
function elgg_tokeninput_get_secret()
{
$secret = elgg_get_plugin_setting('__secret', 'elgg_tokeninput');
if (!$secret) {
$secret = generate_random_cleartext_password();
elgg_set_plugin_setting('__secret', $secret, 'elgg_tokeninput');
}
return $secret;
}
示例15: simplesaml_register_user
/**
* Register a user in Elgg based on information provided by the Service Provider (SP).
*
* @param string $name the (display)name of the new user
* @param string $email the email address of the user
* @param string $saml_source the name of the SP this information came from
* @param bool $validate do we need to validate the email address of this new users
* @param string $username the username provided by the SP (optional)
*
* @return bool|ElggUser the new user, false on failure
*/
function simplesaml_register_user($name, $email, $saml_source, $validate = false, $username = "")
{
$result = false;
if (!empty($name) && !empty($email) && !empty($saml_source)) {
// check which username to use
if (!empty($username)) {
// make sure the username is unique
$username = simplesaml_generate_unique_username($username);
} else {
// create a username from email
$username = simplesaml_generate_username_from_email($email);
}
if (!empty($username)) {
// generate a random password
$password = generate_random_cleartext_password();
try {
$user_guid = register_user($username, $password, $name, $email);
if (!empty($user_guid)) {
$new_user = get_user($user_guid);
if (!$validate) {
// no need for extra validation. We trust this user
elgg_set_user_validation_status($new_user->getGUID(), true, "simplesaml");
}
$params = array("user" => $new_user, "password" => $password, "friend_guid" => null, "invitecode" => null);
if (!elgg_trigger_plugin_hook("register", "user", $params, true)) {
register_error(elgg_echo("registerbad"));
} else {
$result = $new_user;
}
}
} catch (Exception $e) {
register_error($e->getMessage());
}
} else {
register_error(elgg_echo("registration:usernamenotvalid"));
}
}
return $result;
}