本文整理汇总了PHP中check_password_policy函数的典型用法代码示例。如果您正苦于以下问题:PHP check_password_policy函数的具体用法?PHP check_password_policy怎么用?PHP check_password_policy使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_password_policy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validation
function validation($data, $files)
{
global $COURSE, $CFG;
$errors = parent::validation($data, $files);
$textlib = textlib_get_instance();
$name = trim(stripslashes($data['name']));
if ($data['id'] and $group = get_record('groups', 'id', $data['id'])) {
if ($textlib->strtolower($group->name) != $textlib->strtolower($name)) {
if (groups_get_group_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupnameexists', 'group', $name);
}
}
if (!empty($CFG->enrol_manual_usepasswordpolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) {
// enforce password policy only if changing password
$errmsg = '';
if (!check_password_policy($data['enrolmentkey'], $errmsg)) {
$errors['enrolmentkey'] = $errmsg;
}
}
} else {
if (groups_get_group_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupnameexists', 'group', $name);
}
}
return $errors;
}
示例2: validation
function validation($data, $files)
{
global $USER;
$errors = parent::validation($data, $files);
update_login_count();
// ignore submitted username
if (!($user = authenticate_user_login($USER->username, $data['password']))) {
$errors['password'] = get_string('invalidlogin');
return $errors;
}
reset_login_count();
if ($data['newpassword1'] != $data['newpassword2']) {
$errors['newpassword1'] = get_string('passwordsdiffer');
$errors['newpassword2'] = get_string('passwordsdiffer');
return $errors;
}
if ($data['password'] == $data['newpassword1']) {
$errors['newpassword1'] = get_string('mustchangepassword');
$errors['newpassword2'] = get_string('mustchangepassword');
return $errors;
}
$errmsg = '';
//prevents eclipse warnings
if (!check_password_policy($data['newpassword1'], $errmsg)) {
$errors['newpassword1'] = $errmsg;
$errors['newpassword2'] = $errmsg;
return $errors;
}
return $errors;
}
示例3: validation
/**
* Form validation
*
* @param array $data
* @param array $files
* @return array $errors An array of errors
*/
function validation($data, $files)
{
global $COURSE, $DB, $CFG;
$errors = parent::validation($data, $files);
$name = trim($data['name']);
if ($data['id'] and $group = $DB->get_record('groups', array('id' => $data['id']))) {
if (textlib::strtolower($group->name) != textlib::strtolower($name)) {
if (groups_get_group_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupnameexists', 'group', $name);
}
}
if (!empty($CFG->groupenrolmentkeypolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) {
// enforce password policy only if changing password
$errmsg = '';
if (!check_password_policy($data['enrolmentkey'], $errmsg)) {
$errors['enrolmentkey'] = $errmsg;
}
}
} else {
if (groups_get_group_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupnameexists', 'group', $name);
}
}
return $errors;
}
示例4: validation
/**
* Perform extra password change validation.
* @param array $data submitted form fields.
* @param array $files submitted with the form.
* @return array errors occuring during validation.
*/
public function validation($data, $files)
{
global $USER;
$errors = parent::validation($data, $files);
// Ignore submitted username.
if ($data['password'] !== $data['password2']) {
$errors['password'] = get_string('passwordsdiffer');
$errors['password2'] = get_string('passwordsdiffer');
return $errors;
}
$errmsg = '';
// Prevents eclipse warnings.
if (!check_password_policy($data['password'], $errmsg)) {
$errors['password'] = $errmsg;
$errors['password2'] = $errmsg;
return $errors;
}
return $errors;
}
示例5: validation
function validation($data, $files)
{
global $USER;
$errors = parent::validation($data, $files);
update_login_count();
// ignore submitted username
if (!($user = authenticate_user_login($USER->username, $data['password']))) {
$errors['password'] = get_string('invalidlogin');
return $errors;
}
reset_login_count();
if ($data['newpassword1'] != $data['newpassword2']) {
$errors['newpassword1'] = get_string('passwordsdiffer');
$errors['newpassword2'] = get_string('passwordsdiffer');
return $errors;
}
if ($data['password'] == $data['newpassword1']) {
$errors['newpassword1'] = get_string('mustchangepassword');
$errors['newpassword2'] = get_string('mustchangepassword');
return $errors;
}
$errmsg = '';
//prevents eclipse warnings
if (!check_password_policy($data['newpassword1'], $errmsg)) {
$errors['newpassword1'] = $errmsg;
$errors['newpassword2'] = $errmsg;
return $errors;
}
// Added by SMS 8/7/2011: To make sure the password does not include special
// characters that may result in issues when synching the password with vms
if (!isValidPassword($data['newpassword1'])) {
$errors['newpassword1'] .= 'Your password cannot contain the following characters: " / \\ [ ] : ; | = , + * ? < > @ & !';
$errors['newpassword2'] .= 'Your password cannot contain the following characters: " / \\ [ ] : ; | = , + * ? < > @ & !';
}
return $errors;
}
示例6: validation
function validation($usernew, $files)
{
global $CFG;
$usernew = (object) $usernew;
$usernew->username = trim($usernew->username);
$user = get_record('user', 'id', $usernew->id);
$err = array();
if (!empty($usernew->newpassword)) {
$errmsg = '';
//prevent eclipse warning
if (!check_password_policy($usernew->newpassword, $errmsg)) {
$err['newpassword'] = $errmsg;
}
}
if (empty($usernew->username)) {
//might be only whitespace
$err['username'] = get_string('required');
} else {
if (!$user or $user->username !== stripslashes($usernew->username)) {
//check new username does not exist
if (record_exists('user', 'username', $usernew->username, 'mnethostid', $CFG->mnet_localhost_id)) {
$err['username'] = get_string('usernameexists');
}
//check allowed characters
if ($usernew->username !== moodle_strtolower($usernew->username)) {
echo 'grrrr';
$err['username'] = get_string('usernamelowercase');
} else {
if (empty($CFG->extendedusernamechars)) {
$string = eregi_replace("[^(-\\.[:alnum:])]", '', $usernew->username);
if ($usernew->username !== $string) {
$err['username'] = get_string('alphanumerical');
}
}
}
}
}
if (!$user or $user->email !== stripslashes($usernew->email)) {
if (!validate_email(stripslashes($usernew->email))) {
$err['email'] = get_string('invalidemail');
} else {
if (record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) {
$err['email'] = get_string('emailexists');
}
}
}
/// Next the customisable profile fields
$err += profile_validation($usernew, $files);
if (count($err) == 0) {
return true;
} else {
return $err;
}
}
示例7: course_edit_validation
/**
* Validates course edit form data
*
* @param object $instance enrol instance or null if does not exist yet
* @param array $data
* @param object $context context of existing course or parent category if course does not exist
* @return array errors array
*/
public function course_edit_validation($instance, array $data, $context)
{
$errors = array();
if (!has_capability('enrol/guest:config', $context)) {
// we are going to ignore the data later anyway, they would nto be able to fix the form anyway
return $errors;
}
$i = isset($instance->id) ? $instance->id : 0;
if (!isset($data['enrol_guest_status_' . $i])) {
return $errors;
}
$password = empty($data['enrol_guest_password_' . $i]) ? '' : $data['enrol_guest_password_' . $i];
$checkpassword = false;
if ($instance) {
if ($data['enrol_guest_status_' . $i] == ENROL_INSTANCE_ENABLED) {
if ($instance->password !== $password) {
$checkpassword = true;
}
}
} else {
if ($data['enrol_guest_status_' . $i] == ENROL_INSTANCE_ENABLED) {
$checkpassword = true;
}
}
if ($checkpassword) {
$require = $this->get_config('requirepassword');
$policy = $this->get_config('usepasswordpolicy');
if ($require and empty($password)) {
$errors['enrol_guest_password_' . $i] = get_string('required');
} else {
if ($policy) {
$errmsg = '';
//prevent eclipse warning
if (!check_password_policy($password, $errmsg)) {
$errors['enrol_guest_password_' . $i] = $errmsg;
}
}
}
}
return $errors;
}
示例8: validation
public function validation($usernew, $files)
{
global $CFG, $DB;
$usernew = (object) $usernew;
//$usernew->username = trim($usernew->username);
$user = $DB->get_record('user', array('id' => $usernew->id));
$err = array();
/* GWL : Phone no. validation For Moodle User Reg page */
if (!preg_match("/^[0-9]{10}\$/", $usernew->username)) {
$err['username'] = get_string('errorphonenum');
}
/* GWL : Phone no. validation For Moodle User Reg page */
if (!$user and !empty($usernew->createpassword)) {
if ($usernew->suspended) {
// Show some error because we can not mail suspended users.
$err['suspended'] = get_string('error');
}
} else {
if (!empty($usernew->newpassword)) {
$errmsg = '';
// Prevent eclipse warning.
if (!check_password_policy($usernew->newpassword, $errmsg)) {
$err['newpassword'] = $errmsg;
}
} else {
if (!$user) {
$auth = get_auth_plugin($usernew->auth);
if ($auth->is_internal()) {
// Internal accounts require password!
$err['newpassword'] = get_string('required');
}
}
}
}
// Code added by sumit
if ($usernew->managertype != 1 && $usernew->managertype != 3) {
//GWL : Add Instructor
if (empty($usernew->userregion)) {
$errors['userregion'] = get_string('selectregion', 'block_iomad_company_admin');
}
}
// End of code
if (empty($usernew->username)) {
// Might be only whitespace.
$err['username'] = get_string('required');
} else {
if (!$user or $user->username !== $usernew->username) {
// Check new username does not exist.
if ($DB->record_exists('user', array('username' => $usernew->username, 'mnethostid' => $CFG->mnet_localhost_id))) {
$err['username'] = get_string('phonenumexists');
//GWL : Change get_string('usernameexists') to 'phonenumexists'
}
/* GWL : For Phone No. Validation Remove Another Check for username */
/*
// Check allowed characters.
if ($usernew->username !== core_text::strtolower($usernew->username)) {
$err['username'] = get_string('usernamelowercase');
} else {
if ($usernew->username !== clean_param($usernew->username, PARAM_USERNAME)) {
$err['username'] = get_string('invalidusername');
}
}
*/
/* GWL : For Phone No. Validation Remove Another Check for username */
}
}
if (!$user or $user->email !== $usernew->email) {
if (!validate_email($usernew->email)) {
$err['email'] = get_string('invalidemail');
} else {
if ($DB->record_exists('user', array('email' => $usernew->email, 'mnethostid' => $CFG->mnet_localhost_id))) {
$err['email'] = get_string('emailexists');
}
}
}
// Next the customisable profile fields.
$err += profile_validation($usernew, $files);
if (count($err) == 0) {
return true;
} else {
return $err;
}
}
示例9: validation
/**
* Validate the form data.
* @param array $usernew
* @param array $files
* @return array|bool
*/
public function validation($usernew, $files)
{
global $CFG, $DB;
$usernew = (object) $usernew;
$usernew->username = trim($usernew->username);
$user = $DB->get_record('user', array('id' => $usernew->id));
$err = array();
if (!$user and !empty($usernew->createpassword)) {
if ($usernew->suspended) {
// Show some error because we can not mail suspended users.
$err['suspended'] = get_string('error');
}
} else {
if (!empty($usernew->newpassword)) {
$errmsg = '';
// Prevent eclipse warning.
if (!check_password_policy($usernew->newpassword, $errmsg)) {
$err['newpassword'] = $errmsg;
}
} else {
if (!$user) {
$auth = get_auth_plugin($usernew->auth);
if ($auth->is_internal()) {
// Internal accounts require password!
$err['newpassword'] = get_string('required');
}
}
}
}
if (empty($usernew->username)) {
// Might be only whitespace.
$err['username'] = get_string('required');
} else {
if (!$user or $user->username !== $usernew->username) {
// Check new username does not exist.
if ($DB->record_exists('user', array('username' => $usernew->username, 'mnethostid' => $CFG->mnet_localhost_id))) {
$err['username'] = get_string('usernameexists');
}
// Check allowed characters.
if ($usernew->username !== core_text::strtolower($usernew->username)) {
$err['username'] = get_string('usernamelowercase');
} else {
if ($usernew->username !== clean_param($usernew->username, PARAM_USERNAME)) {
$err['username'] = get_string('invalidusername');
}
}
}
}
if (!$user or isset($usernew->email) && $user->email !== $usernew->email) {
if (!validate_email($usernew->email)) {
$err['email'] = get_string('invalidemail');
} else {
if (empty($CFG->allowaccountssameemail) and $DB->record_exists('user', array('email' => $usernew->email, 'mnethostid' => $CFG->mnet_localhost_id))) {
$err['email'] = get_string('emailexists');
}
}
}
// Next the customisable profile fields.
$err += profile_validation($usernew, $files);
if (count($err) == 0) {
return true;
} else {
return $err;
}
}
示例10: validation
function validation($data, $files)
{
global $CFG, $DB;
$errors = parent::validation($data, $files);
$authplugin = get_auth_plugin($CFG->registerauth);
if ($DB->record_exists('user', array('username' => $data['username'], 'mnethostid' => $CFG->mnet_localhost_id))) {
$errors['username'] = get_string('usernameexists');
} else {
//check allowed characters
if ($data['username'] !== moodle_strtolower($data['username'])) {
$errors['username'] = get_string('usernamelowercase');
} else {
if ($data['username'] !== clean_param($data['username'], PARAM_USERNAME)) {
$errors['username'] = get_string('invalidusername');
}
}
}
//check if user exists in external db
//TODO: maybe we should check all enabled plugins instead
if ($authplugin->user_exists($data['username'])) {
$errors['username'] = get_string('usernameexists');
}
if (!validate_email($data['email'])) {
$errors['email'] = get_string('invalidemail');
} else {
if ($DB->record_exists('user', array('email' => $data['email']))) {
$errors['email'] = get_string('emailexists') . ' <a href="forgot_password.php">' . get_string('newpassword') . '?</a>';
}
}
if (empty($data['email2'])) {
$errors['email2'] = get_string('missingemail');
} else {
if ($data['email2'] != $data['email']) {
$errors['email2'] = get_string('invalidemail');
}
}
if (!isset($errors['email'])) {
if ($err = email_is_not_allowed($data['email'])) {
$errors['email'] = $err;
}
}
$errmsg = '';
if (!check_password_policy($data['password'], $errmsg)) {
$errors['password'] = $errmsg;
}
if ($this->signup_captcha_enabled()) {
$recaptcha_element = $this->_form->getElement('recaptcha_element');
if (!empty($this->_form->_submitValues['recaptcha_challenge_field'])) {
$challenge_field = $this->_form->_submitValues['recaptcha_challenge_field'];
$response_field = $this->_form->_submitValues['recaptcha_response_field'];
if (true !== ($result = $recaptcha_element->verify($challenge_field, $response_field))) {
$errors['recaptcha'] = $result;
}
} else {
$errors['recaptcha'] = get_string('missingrecaptchachallengefield');
}
}
return $errors;
}
示例11: edit_instance_validation
/**
* Perform custom validation of the data used to edit the instance.
*
* @param array $data array of ("fieldname"=>value) of submitted data
* @param array $files array of uploaded files "element_name"=>tmp_file_path
* @param object $instance The instance loaded from the DB
* @param context $context The context of the instance we are editing
* @return array of "element_name"=>"error_description" if there are errors,
* or an empty array if everything is OK.
* @return void
*/
public function edit_instance_validation($data, $files, $instance, $context)
{
$errors = array();
$checkpassword = false;
if ($data['id']) {
// Check the password if we are enabling the plugin again.
if ($instance->status == ENROL_INSTANCE_DISABLED && $data['status'] == ENROL_INSTANCE_ENABLED) {
$checkpassword = true;
}
// Check the password if the instance is enabled and the password has changed.
if ($data['status'] == ENROL_INSTANCE_ENABLED && $instance->password !== $data['password']) {
$checkpassword = true;
}
} else {
$checkpassword = true;
}
if ($checkpassword) {
$require = $this->get_config('requirepassword');
$policy = $this->get_config('usepasswordpolicy');
if ($require && trim($data['password']) === '') {
$errors['password'] = get_string('required');
} else {
if (!empty($data['password']) && $policy) {
$errmsg = '';
if (!check_password_policy($data['password'], $errmsg)) {
$errors['password'] = $errmsg;
}
}
}
}
$validstatus = array_keys($this->get_status_options());
$tovalidate = array('status' => $validstatus);
$typeerrors = $this->validate_param_types($data, $tovalidate);
$errors = array_merge($errors, $typeerrors);
return $errors;
}
示例12: get_string
}
// do not update record if new auth plugin does not exist!
if (!in_array($existinguser->auth, $availableauths)) {
$upt->track('auth', get_string('userautherror', 'error', $existinguser->auth), 'error');
$upt->track('status', $strusernotupdated, 'error');
$userserrors++;
continue;
} else if (!in_array($existinguser->auth, $allowedauths)) {
$upt->track('auth', $struserauthunsupported, 'warning');
}
$auth = get_auth_plugin($existinguser->auth);
$isinternalauth = $auth->is_internal();
if ($isinternalauth && $updatepasswords && !check_password_policy($user->password, $errmsg)) {
$upt->track('password', get_string('internalauthpassworderror', 'error', $existinguser->password), 'error');
$upt->track('status', $strusernotupdated, 'error');
$userserrors++;
continue;
} else {
$forcechangepassword = true;
}
if (!$isinternalauth) {
$existinguser->password = 'not cached';
$upt->track('password', 'not cached');
$forcechangepassword = false;
} else if ($updatepasswords){
$existinguser->password = hash_internal_user_password($existinguser->password);
} else {
示例13: validation
function validation($usernew, $files) {
global $CFG, $DB;
$usernew = (object)$usernew;
$usernew->username = trim($usernew->username);
$user = $DB->get_record('user', array('id'=>$usernew->id));
$err = array();
if (!empty($usernew->newpassword)) {
$errmsg = '';//prevent eclipse warning
if (!check_password_policy($usernew->newpassword, $errmsg)) {
$err['newpassword'] = $errmsg;
}
}
if (empty($usernew->username)) {
//might be only whitespace
$err['username'] = get_string('required');
} else if (!$user or $user->username !== $usernew->username) {
//check new username does not exist
if ($DB->record_exists('user', array('username'=>$usernew->username, 'mnethostid'=>$CFG->mnet_localhost_id))) {
$err['username'] = get_string('usernameexists');
}
//check allowed characters
if ($usernew->username !== textlib::strtolower($usernew->username)) {
$err['username'] = get_string('usernamelowercase');
} else {
if ($usernew->username !== clean_param($usernew->username, PARAM_USERNAME)) {
$err['username'] = get_string('invalidusername');
}
}
}
if (!$user or $user->email !== $usernew->email) {
if (!validate_email($usernew->email)) {
$err['email'] = get_string('invalidemail');
} else if ($DB->record_exists('user', array('email'=>$usernew->email, 'mnethostid'=>$CFG->mnet_localhost_id))) {
$err['email'] = get_string('emailexists');
}
}
/// Next the customisable profile fields
$err += profile_validation($usernew, $files);
if (count($err) == 0){
return true;
} else {
return $err;
}
}
示例14: get_final_create_data
/**
* Assemble the user data based on defaults.
* This returns the final data to be passed to proceed().
*
* @param array data current data.
* @return array.
*/
protected function get_final_create_data($data)
{
global $CFG, $DB, $UUC_DEFAULTS, $UUC_SUPPORTEDAUTHS;
$data->confirmed = 1;
$data->timemodified = time();
$data->timecreated = time();
// Only local accounts. Huh?
$data->mnethostid = $CFG->mnet_localhost_id;
if (!isset($data->suspended) || $data->suspended === '') {
$data->suspended = 0;
} else {
$data->suspended = $data->suspended ? 1 : 0;
}
if (empty($data->auth)) {
$data->auth = empty($UUC_DEFAULTS['auth']) ? 'manual' : $UUC_DEFAULTS['auth'];
}
try {
$auth = get_auth_plugin($data->auth);
} catch (Exception $e) {
$this->error('userautherror', new lang_string('userautherror', 'error', s($data->auth)));
return false;
}
if (!isset($UUC_SUPPORTEDAUTHS[$data->auth])) {
$this->set_status('userauthunsupported', new lang_string('userauthunsupported', 'warning'));
}
$isinternalauth = $auth->is_internal();
if ($DB->record_exists('user', array('email' => $data->email))) {
if ($this->importoptions['noemailduplicates']) {
$this->error('useremailduplicate', new lang_string('useremailduplicate', 'error'));
return false;
} else {
$this->set_status('useremailduplicate', new lang_string('useremailduplicate', 'error'));
}
}
if (!validate_email($data->email)) {
$this->set_status('invalidemail', new lang_string('invalidemail'));
}
if (empty($data->lang)) {
$data->lang = empty($UUC_DEFAULTS['lang']) ? '' : $UUC_DEFAULTS['lang'];
} else {
if (clean_param($data->lang, PARAM_LANG) === '') {
$this->set_status('cannotfindlang', new lang_string('cannotfindlang', 'error', $data->lang));
$data->lang = empty($UUC_DEFAULTS['lang']) ? '' : $UUC_DEFAULTS['lang'];
}
}
$this->needpasswordchange = false;
if ($isinternalauth) {
if (empty($data->password)) {
if ($this->importoptions['passwordmode'] === tool_uploadusercli_processor::PASSWORD_MODE_GENERATE) {
$data->password = 'to be generated';
} else {
$this->error('missingfield', new lang_string('missingfield', 'error', 'password'));
return false;
}
} else {
$errmsg = NULL;
$weak = !check_password_policy($data->password, $errmsg);
if ($this->importoptions['forcepasswordchange'] == tool_uploadusercli_processor::FORCE_PASSWORD_CHANGE_ALL || $this->reset_password() && $weak) {
$this->needpasswordchange = true;
}
// Use a low cost factor when generating hash so it's not too
// slow when uploading lots of users. Hashes will be
// automatically updated the first time the user logs in.
$data->password = hash_internal_user_password($data->password, true);
}
} else {
$data->password = AUTH_PASSWORD_NOT_CACHED;
}
// insert_record only keeps the valid fields for the record
//$data->id = user_create_user($data, false, false);
return $data;
}
示例15: user_update_user
/**
* Update a user with a user object (will compare against the ID)
*
* @param stdClass $user the user to update
* @param bool $updatepassword if true, authentication plugin will update password.
*/
function user_update_user($user, $updatepassword = true)
{
global $DB;
// set the timecreate field to the current time
if (!is_object($user)) {
$user = (object) $user;
}
//check username
if (isset($user->username)) {
if ($user->username !== core_text::strtolower($user->username)) {
throw new moodle_exception('usernamelowercase');
} else {
if ($user->username !== clean_param($user->username, PARAM_USERNAME)) {
throw new moodle_exception('invalidusername');
}
}
}
// Unset password here, for updating later, if password update is required.
if ($updatepassword && isset($user->password)) {
//check password toward the password policy
if (!check_password_policy($user->password, $errmsg)) {
throw new moodle_exception($errmsg);
}
$passwd = $user->password;
unset($user->password);
}
$user->timemodified = time();
$DB->update_record('user', $user);
if ($updatepassword) {
// Get full user record.
$updateduser = $DB->get_record('user', array('id' => $user->id));
// if password was set, then update its hash
if (isset($passwd)) {
$authplugin = get_auth_plugin($updateduser->auth);
if ($authplugin->can_change_password()) {
$authplugin->user_update_password($updateduser, $passwd);
}
}
}
// Trigger event.
$event = \core\event\user_updated::create(array('objectid' => $user->id, 'context' => context_user::instance($user->id)));
$event->trigger();
}