Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AUTH_PASSWORD_GENERATE event added #230

Merged
merged 3 commits into from Jun 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 32 additions & 18 deletions inc/auth.php
Expand Up @@ -678,27 +678,41 @@ function auth_nameencode($name, $skip_group = false) {
/**
* Create a pronouncable password
*
* @author Andreas Gohr <andi@splitbrain.org>
* @link http://www.phpbuilder.com/annotate/message.php3?id=1014451
* The $foruser variable might be used by plugins to run additional password
* policy checks, but is not used by the default implementation
*
* @author Andreas Gohr <andi@splitbrain.org>
* @link http://www.phpbuilder.com/annotate/message.php3?id=1014451
* @triggers AUTH_PASSWORD_GENERATE
*
* @param string $foruser username for which the password is generated
* @return string pronouncable password
*/
function auth_pwgen() {
$pw = '';
$c = 'bcdfghjklmnprstvwz'; //consonants except hard to speak ones
$v = 'aeiou'; //vowels
$a = $c.$v; //both

//use two syllables...
for($i = 0; $i < 2; $i++) {
$pw .= $c[rand(0, strlen($c) - 1)];
$pw .= $v[rand(0, strlen($v) - 1)];
$pw .= $a[rand(0, strlen($a) - 1)];
function auth_pwgen($foruser = '') {
$data = array(
'password' => '',
'foruser' => $foruser
);

$evt = new Doku_Event('AUTH_PASSWORD_GENERATE', $data);
if($evt->advise_before(true)) {
$c = 'bcdfghjklmnprstvwz'; //consonants except hard to speak ones
$v = 'aeiou'; //vowels
$a = $c.$v; //both
$s = '!$%&?+*~#-_:.;,'; // specials

//use thre syllables...
for($i = 0; $i < 3; $i++) {
$data['password'] .= $c[mt_rand(0, strlen($c) - 1)];
$data['password'] .= $v[mt_rand(0, strlen($v) - 1)];
$data['password'] .= $a[mt_rand(0, strlen($a) - 1)];
}
//... and add a nice number and special
$data['password'] .= mt_rand(10, 99).$s[mt_rand(0, strlen($s) - 1)];
}
//... and add a nice number
$pw .= rand(10, 99);
$evt->advise_after();

return $pw;
return $data['password'];
}

/**
Expand Down Expand Up @@ -765,7 +779,7 @@ function register() {
}

if($conf['autopasswd']) {
$pass = auth_pwgen(); // automatically generate password
$pass = auth_pwgen($login); // automatically generate password
} elseif(empty($pass) || empty($passchk)) {
msg($lang['regmissing'], -1); // complain about missing passwords
return false;
Expand Down Expand Up @@ -958,7 +972,7 @@ function act_resendpwd() {

} else { // autogenerate the password and send by mail

$pass = auth_pwgen();
$pass = auth_pwgen($user);
if(!$auth->triggerUserMod('modify', array($user, array('pass' => $pass)))) {
msg('error modifying user data', -1);
return false;
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/usermanager/admin.php
Expand Up @@ -355,7 +355,7 @@ function _addUser(){
if ($this->_auth->canDo('modPass')){
if (empty($pass)){
if($INPUT->has('usernotify')){
$pass = auth_pwgen();
$pass = auth_pwgen($user);
} else {
msg($this->lang['add_fail'], -1);
return false;
Expand Down Expand Up @@ -496,7 +496,7 @@ function _modifyUser(){

// generate password if left empty and notification is on
if($INPUT->has('usernotify') && empty($newpass)){
$newpass = auth_pwgen();
$newpass = auth_pwgen($olduser);
}

if (!empty($newpass) && $this->_auth->canDo('modPass'))
Expand Down