function force_password_change_check in Force Password Change 6.3
Same name and namespace in other branches
- 7.2 force_password_change.module \force_password_change_check()
- 7 force_password_change.module \force_password_change_check()
2 calls to force_password_change_check()
- force_password_change_init in ./
force_password_change.module - Implementation of hook_init()
- force_password_change_user in ./
force_password_change.module - Implementation of hook_user()
File
- ./
force_password_change.module, line 87
Code
function force_password_change_check() {
global $user;
$change_password_url = preg_replace('/!uid/', $user->uid, variable_get('change_password_url', 'user/!uid/edit'));
if ($user->force_password_change) {
return '1';
}
elseif (variable_get('expire_password', TRUE)) {
$expiry_data = db_result(db_query_range('SELECT fpce.expiry ' . 'FROM {force_password_change_expiry} AS fpce ' . 'LEFT JOIN {users_roles} AS ur ' . 'ON ur.rid = fpce.rid ' . 'WHERE ur.uid = %d OR fpce.rid = 2 ' . 'ORDER BY fpce.weight ', $user->uid, 0, 1));
if ($expiry_data) {
$pass_change_data = db_fetch_array(db_query('SELECT fpcu.last_password_change, u.created ' . 'FROM {force_password_change_users} AS fpcu ' . 'JOIN {users} AS u ' . 'ON u.uid = fpcu.uid ' . 'WHERE u.uid = %d ', $user->uid));
if ($pass_change_data['last_password_change'] != '' && time() - $expiry_data > $pass_change_data['last_password_change'] || $pass_change_data['last_password_change'] == '' && time() - $expiry_data > $pass_change_data['created']) {
$expires = $expiry_data;
$year = 60 * 60 * 24 * 365;
if ($expires % $year === 0) {
$time_period = $expires / $year;
$time_period = $time_period > 1 ? $time_period . ' ' . t('years') : t('year');
}
else {
$week = 60 * 60 * 24 * 7;
if ($expires % $week === 0) {
$time_period = $expires / $week;
$time_period = $time_period > 1 ? $time_period . ' ' . t('weeks') : t('week');
}
else {
$day = 60 * 60 * 24;
if ($expires % $day === 0) {
$time_period = $expires / $day;
$time_period = $time_period > 1 ? $time_period . ' ' . t('days') : t('day');
}
else {
$hour = 60 * 60;
if ($expires % $hour === 0) {
$time_period = $expires / $hour;
$time_period = $time_period > 1 ? $time_period . ' ' . t('hours') : t('hour');
}
}
}
}
db_query('UPDATE {users} SET force_password_change = 1 WHERE uid = %d', $user->uid);
return $time_period;
}
}
}
return FALSE;
}