Lines Matching +full:update +full:- +full:user +full:- +full:pass -(+path:inc +path:lang) -(+path:lib +path:plugins +path:lang) -(+path:lib +path:tpl +path:dokuwiki +path:lang)

7  * a user by calling auth_login()
53 foreach ($plugin_controller->getList('auth') as $plugin) {
55 $auth = $plugin_controller->load('auth', $plugin);
61 msg($lang['authtempfail'], -1);
65 if ($auth->success == false) {
66 // degrade to unauthenticated user
69 msg($lang['authtempfail'], -1);
74 $INPUT->set('http_credentials', false);
75 if (!$conf['rememberme']) $INPUT->set('r', false);
77 // Populate Basic Auth user/password from Authorization header
79 $header = $INPUT->server->str('HTTP_AUTHORIZATION') ?: $INPUT->server->str('REDIRECT_HTTP_AUTHORIZATION');
80 if (preg_match('~^Basic ([a-z\d/+]*={0,2})$~i', $header, $matches)) {
86 if (!$INPUT->str('u') && empty($_COOKIE[DOKU_COOKIE]) && !empty($INPUT->server->str('PHP_AUTH_USER'))) {
87 $INPUT->set('u', $INPUT->server->str('PHP_AUTH_USER'));
88 $INPUT->set('p', $INPUT->server->str('PHP_AUTH_PW'));
89 $INPUT->set('http_credentials', true);
92 // apply cleaning (auth specific user names, remove control chars)
93 if (true === $auth->success) {
94 $INPUT->set('u', $auth->cleanUser(stripctl($INPUT->str('u'))));
95 $INPUT->set('p', stripctl($INPUT->str('p')));
101 if ($auth instanceof AuthPlugin && $auth->canDo('external')) {
102 $ok = $auth->trustExternal($INPUT->str('u'), $INPUT->str('p'), $INPUT->bool('r'));
109 'user' => $INPUT->str('u'),
110 'password' => $INPUT->str('p'),
111 'sticky' => $INPUT->bool('r'),
112 'silent' => $INPUT->bool('http_credentials')
125 * Loads the ACL setup and handle user wildcards
148 // substitute user wildcard first (its 1:1)
149 if (strstr($line, '%USER%')) {
150 // if user is not logged in, this ACL line is meaningless - skip it
151 if (!$INPUT->server->has('REMOTE_USER')) continue;
153 $id = str_replace('%USER%', cleanID($INPUT->server->str('REMOTE_USER')), $id);
154 $rest = str_replace('%USER%', auth_nameencode($INPUT->server->str('REMOTE_USER')), $rest);
159 // if user is not logged in, grps is empty, no output will be added (i.e. skipped)
195 $header = $INPUT->server->str('HTTP_AUTHORIZATION');
205 msg(hsc($e->getMessage()), -1);
209 // fetch user info from backend
210 $user = $authtoken->getUser();
211 $USERINFO = $auth->getUserData($user);
214 // the code is correct, set up user
215 $INPUT->server->set('REMOTE_USER', $user);
216 $_SESSION[DOKU_COOKIE]['auth']['user'] = $user;
217 $_SESSION[DOKU_COOKIE]['auth']['pass'] = 'nope';
233 $evdata['user'],
241 * This tries to login the user based on the sent auth credentials
244 * a new login is assumed and user/password are checked. If they
246 * together with the username in a cookie - the same info is stored
252 * no further testing is done and the user is accepted
261 * @param string $user Username
262 * @param string $pass Cleartext Password
270 function auth_login($user, $pass, $sticky = false, $silent = false)
282 if (!empty($user)) {
284 if (!empty($pass) && $auth->checkPass($user, $pass)) {
286 $INPUT->server->set('REMOTE_USER', $user);
287 $secret = auth_cookiesalt(!$sticky, true); //bind non-sticky to session
288 auth_setCookie($user, auth_encrypt($pass, $secret), $sticky);
291 //invalid credentials - log off
294 msg($lang['badlogin'], -1);
301 [$user, $sticky, $pass] = auth_getCookie();
302 if ($user && $pass) {
303 // we got a cookie - see if we can trust it
310 $auth->useSessionCache($user) &&
311 ($session['time'] >= time() - $conf['auth_security_timeout']) &&
312 ($session['user'] == $user) &&
313 ($session['pass'] == sha1($pass)) && //still crypted
316 // he has session, cookie and browser right - let him in
317 $INPUT->server->set('REMOTE_USER', $user);
322 // no we don't trust it yet - recheck pass but silent
323 $secret = auth_cookiesalt(!$sticky, true); //bind non-sticky to session
324 $pass = auth_decrypt($pass, $secret);
325 return auth_login($user, $pass, $sticky, true);
336 * This is neither unique nor unfakable - still it adds some
354 $INPUT->server->str('HTTP_USER_AGENT'),
355 $INPUT->server->str('HTTP_ACCEPT_LANGUAGE'),
441 $cipher->setPassword($secret, 'pbkdf2', 'sha1', 'phpseclib');
442 $cipher->setIV($iv);
446 http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf, Appendix C
450 return $cipher->encrypt($iv . $data);
466 $cipher->setPassword($secret, 'pbkdf2', 'sha1', 'phpseclib');
467 $cipher->setIV($iv);
470 return $cipher->decrypt(substr($ciphertext, 16));
478 * Log out the current user
480 * This clears all authentication data and thus log the user
485 * @param bool $keepbc - when true, the breadcrumb data is not cleared
499 if (isset($_SESSION[DOKU_COOKIE]['auth']['user']))
500 unset($_SESSION[DOKU_COOKIE]['auth']['user']);
501 if (isset($_SESSION[DOKU_COOKIE]['auth']['pass']))
502 unset($_SESSION[DOKU_COOKIE]['auth']['pass']);
507 $INPUT->server->remove('REMOTE_USER');
512 'expires' => time() - 600000,
520 $auth->logOff();
525 * Check if a user is a manager
528 * user.
532 * @param string $user Username
533 * @param array $groups List of groups the user is in
534 * @param bool $adminonly when true checks if user is admin
541 function auth_ismanager($user = null, $groups = null, $adminonly = false, $recache = false)
552 if (is_null($user)) {
553 if (!$INPUT->server->has('REMOTE_USER')) {
556 $user = $INPUT->server->str('REMOTE_USER');
560 // checking the logged in user, or another one?
561 if ($USERINFO && $user === $INPUT->server->str('REMOTE_USER')) {
564 $groups = $auth->getUserData($user);
571 $cachekey = serialize([$user, $adminonly, $groups]);
574 $ok = auth_isMember($conf['superuser'], $user, $groups);
578 $ok = auth_isMember($conf['manager'], $user, $groups);
588 * Check if a user is admin
594 * @param string $user Username
595 * @param array $groups List of groups the user is in
602 function auth_isadmin($user = null, $groups = null, $recache = false)
604 return auth_ismanager($user, $groups, true, $recache);
608 * Match a user and his groups against a comma separated list of
614 * @param string $user user to match against
615 * @param array $groups groups the user is member of
618 function auth_isMember($memberlist, $user, array $groups)
624 // clean user and groups
625 if (!$auth->isCaseSensitive()) {
626 $user = PhpString::strtolower($user);
629 $user = $auth->cleanUser($user);
641 if (!$auth->isCaseSensitive()) $member = PhpString::strtolower($member);
643 $member = $auth->cleanGroup(substr($member, 1));
646 $member = $auth->cleanUser($member);
647 if ($member == $user) return true;
658 * This checks the permissions for the current user
673 return auth_aclcheck($id, $INPUT->server->str('REMOTE_USER'), is_array($USERINFO) ? $USERINFO['grps'] : []);
677 * Returns the maximum rights a user has for the given ID or its namespace
683 * @param string $user Username
684 * @param array|null $groups Array of groups the user is in
687 function auth_aclcheck($id, $user, $groups)
691 'user' => $user,
711 $user =& $data['user'];
727 //if user is superuser or in superusergroup return 255 (acl_admin)
728 if (auth_isadmin($user, $groups)) {
732 if (!$auth->isCaseSensitive()) {
733 $user = PhpString::strtolower($user);
736 $user = auth_nameencode($auth->cleanUser($user));
745 $perm = -1;
750 //add User
751 if ($user) $groups[] = $user;
759 if (!$auth->isCaseSensitive() && $acl[1] !== '@ALL') {
770 if ($perm > -1) {
771 //we had a match - return it
789 if (!$auth->isCaseSensitive() && $acl[1] !== '@ALL') {
800 //we had a match - return it
801 if ($perm != -1) {
825 * Some auth backends allow special chars in their user and groupnames
827 * are encoded UTF-8 multibyte are left as is (different from usual
846 if ($name == '%USER%') return $name;
852 '/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f])/',
858 '/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f])/',
876 return '%' . dechex(ord(substr($matches[1], -1)));
902 if ($evt->advise_before(true)) {
906 $s = '!$%&?+*~#-_:.;,'; // specials
910 $data['password'] .= $c[auth_random(0, strlen($c) - 1)];
911 $data['password'] .= $v[auth_random(0, strlen($v) - 1)];
912 $data['password'] .= $a[auth_random(0, strlen($a) - 1)];
915 $data['password'] .= $s[auth_random(0, strlen($s) - 1)] . auth_random(10, 99);
917 $evt->advise_after();
923 * Sends a password to the given user
927 * @param string $user Login name of the user
931 function auth_sendPassword($user, $password)
938 $user = $auth->cleanUser($user);
939 $userinfo = $auth->getUserData($user, false);
946 'LOGIN' => $user,
951 $mail->to($mail->getCleanName($userinfo['name']) . ' <' . $userinfo['mail'] . '>');
952 $mail->subject($lang['regpwmail']);
953 $mail->setBody($text, $trep);
954 return $mail->send();
958 * Register a new user
960 * This registers a new user - Data is read directly from $_POST
975 if (!$INPUT->post->bool('save')) return false;
979 $login = trim($auth->cleanUser($INPUT->post->str('login')));
980 $fullname = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/', '', $INPUT->post->str('fullname')));
981 $email = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/', '', $INPUT->post->str('email')));
982 $pass = $INPUT->post->str('pass');
983 $passchk = $INPUT->post->str('passchk');
986 msg($lang['regmissing'], -1);
991 $pass = auth_pwgen($login); // automatically generate password
992 } elseif (empty($pass) || empty($passchk)) {
993 msg($lang['regmissing'], -1); // complain about missing passwords
995 } elseif ($pass != $passchk) {
996 msg($lang['regbadpass'], -1); // complain about misspelled passwords
1002 msg($lang['regbadmail'], -1);
1006 //okay try to create the user
1007 if (!$auth->triggerUserMod('create', [$login, $pass, $fullname, $email])) {
1008 msg($lang['regfail'], -1);
1012 // send notification about the new user
1014 $subscription->sendRegister($login, $fullname, $email);
1022 // autogenerated password? then send password to user
1023 if (auth_sendPassword($login, $pass)) {
1027 msg($lang['regmailfail'], -1);
1033 * Update user profile
1048 if (!$INPUT->post->bool('save')) return false;
1052 msg($lang['profna'], -1);
1057 $changes['pass'] = $INPUT->post->str('newpass');
1058 $changes['name'] = $INPUT->post->str('fullname');
1059 $changes['mail'] = $INPUT->post->str('email');
1062 if ($changes['pass'] != $INPUT->post->str('passchk')) {
1063 msg($lang['regbadpass'], -1);
1068 $changes['name'] = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/', '', $changes['name']));
1069 $changes['mail'] = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/', '', $changes['mail']));
1073 (empty($changes['name']) && $auth->canDo('modName')) ||
1074 (empty($changes['mail']) && $auth->canDo('modMail'))
1076 msg($lang['profnoempty'], -1);
1079 if (!mail_isvalid($changes['mail']) && $auth->canDo('modMail')) {
1080 msg($lang['regbadmail'], -1);
1087 if (!$auth->canDo('modName')) unset($changes['name']);
1088 if (!$auth->canDo('modMail')) unset($changes['mail']);
1089 if (!$auth->canDo('modPass')) unset($changes['pass']);
1093 msg($lang['profnochange'], -1);
1098 if (!$auth->checkPass($INPUT->server->str('REMOTE_USER'), $INPUT->post->str('oldpass'))) {
1099 msg($lang['badpassconfirm'], -1);
1104 if (!$auth->triggerUserMod('modify', [$INPUT->server->str('REMOTE_USER'), &$changes])) {
1105 msg($lang['proffail'], -1);
1109 if (array_key_exists('pass', $changes) && $changes['pass']) {
1110 // update cookie and session with the changed data
1111 [/* user */, $sticky, /* pass */] = auth_getCookie();
1112 $pass = auth_encrypt($changes['pass'], auth_cookiesalt(!$sticky, true));
1113 auth_setCookie($INPUT->server->str('REMOTE_USER'), $pass, (bool) $sticky);
1126 * Delete the current logged-in user
1139 if (!$INPUT->post->bool('delete')) return false;
1143 if (!actionOK('profile_delete') || !$auth->canDo('delUser')) {
1144 msg($lang['profnodelete'], -1);
1148 if (!$INPUT->post->bool('confirm_delete')) {
1149 msg($lang['profconfdeletemissing'], -1);
1154 if (!$auth->checkPass($INPUT->server->str('REMOTE_USER'), $INPUT->post->str('oldpass'))) {
1155 msg($lang['badpassconfirm'], -1);
1161 $deleted[] = $INPUT->server->str('REMOTE_USER');
1162 if ($auth->triggerUserMod('delete', [$deleted])) {
1176 * - handling the first request of password reset
1177 * - validating the password reset auth token
1196 msg($lang['resendna'], -1);
1200 $token = preg_replace('/[^a-f0-9]+/', '', $INPUT->str('pwauth'));
1203 // we're in token phase - get user info from token
1207 msg($lang['resendpwdbadauth'], -1);
1208 $INPUT->remove('pwauth');
1212 if ((time() - filemtime($tfile)) > (3 * 60 * 60 * 24)) {
1213 msg($lang['resendpwdbadauth'], -1);
1214 $INPUT->remove('pwauth');
1219 $user = io_readfile($tfile);
1220 $userinfo = $auth->getUserData($user, false);
1222 msg($lang['resendpwdnouser'], -1);
1226 if (!$conf['autopasswd']) { // we let the user choose a password
1227 $pass = $INPUT->str('pass');
1230 if (!$pass) return false;
1231 if ($pass != $INPUT->str('passchk')) {
1232 msg($lang['regbadpass'], -1);
1237 if (!$auth->triggerUserMod('modify', [$user, ['pass' => $pass]])) {
1238 msg($lang['proffail'], -1);
1242 $pass = auth_pwgen($user);
1243 if (!$auth->triggerUserMod('modify', [$user, ['pass' => $pass]])) {
1244 msg($lang['proffail'], -1);
1248 if (auth_sendPassword($user, $pass)) {
1251 msg($lang['regmailfail'], -1);
1260 if (!$INPUT->post->bool('save')) return false;
1262 if (!$INPUT->post->str('login')) {
1263 msg($lang['resendpwdmissing'], -1);
1266 $user = trim($auth->cleanUser($INPUT->post->str('login')));
1269 $userinfo = $auth->getUserData($user, false);
1271 msg($lang['resendpwdnouser'], -1);
1280 io_saveFile($tfile, $user);
1283 $trep = ['FULLNAME' => $userinfo['name'], 'LOGIN' => $user, 'CONFIRM' => $url];
1286 $mail->to($userinfo['name'] . ' <' . $userinfo['mail'] . '>');
1287 $mail->subject($lang['regpwmail']);
1288 $mail->setBody($text, $trep);
1289 if ($mail->send()) {
1292 msg($lang['regmailfail'], -1);
1317 $pass = new PassHash();
1320 if (!method_exists($pass, $call)) {
1321 msg("Unsupported crypt method $method", -1);
1325 return $pass->$call($clear, $salt);
1340 $pass = new PassHash();
1341 return $pass->verify_hash($clear, $crypt);
1345 * Set the authentication cookie and add user identification data to the session
1347 * @param string $user username
1348 * @param string $pass encrypted password
1352 function auth_setCookie($user, $pass, $sticky)
1360 $USERINFO = $auth->getUserData($user);
1363 $cookie = base64_encode($user) . '|' . ((int) $sticky) . '|' . base64_encode($pass);
1375 $_SESSION[DOKU_COOKIE]['auth']['user'] = $user;
1376 $_SESSION[DOKU_COOKIE]['auth']['pass'] = sha1($pass);
1385 * Returns the user, (encrypted) password and sticky bit from cookie
1394 [$user, $sticky, $pass] = sexplode('|', $_COOKIE[DOKU_COOKIE], 3, '');
1396 $pass = base64_decode($pass);
1397 $user = base64_decode($user);
1398 return [$user, $sticky, $pass];