141c141,194 < $url = &TWiki::getOopsUrl( $webName, $wikiName, "oopsresetpasswd", $theCryptPassword ); --- > > # If the user's home topic is writable by TWikiGuest, anyone > # can change the user's email address and reset his/her > # password > > #if( &TWiki::Access::checkAccessPermission( "change", "Main.TWikiGuest", "", $wikiName, $TWiki::mainWebname )) { > # $url = &TWiki::getOopsUrl( $webName, $topic, "oopscantchangeresetifwritablehome" ); > # TWiki::redirect( $query, $url ); > # return; > #} > > # Update: doesn't make sense to perform this check - > # if the home topic is writable by all, you can change the > # email address as TWikiGuest and them make the topic > # writable only by the user. > > # Solution: all webs must be writable only by their owners > > > # The command to generate a password > $PASSWD_GEN_CMD="./pwgen 8 1"; > > # Generate the new password > $genPassword=`$PASSWD_GEN_CMD`; > chop $genPassword; > > # Get old password > my $oldcrypt = htpasswdReadPasswd( $wikiName ); > > # Build old and new .htpasswd entries > my $oldCryptPassword = "$wikiName\:$oldcrypt"; > my $theCryptPassword = &htpasswdGeneratePasswd( $wikiName, $genPassword ); > > # Update .htpasswd > htpasswdAddUser( $oldCryptPassword, $theCryptPassword ); > > # Get email addresses for user > my @emails = TWiki::getEmailOfUser($wikiName); > my $emailsStr = join ', ', @emails; # Join together into single string > > # Get email parameters > my $skin = TWiki::Prefs::getPreferencesValue( "SKIN" ); > > > # Construct email > $text = &TWiki::Store::readTemplate( "mailresetpassword", $skin ); > $text =~ s/%EMAILTO%/$emailsStr/go; > $text =~ s/%PASSWORD%/$genPassword/go; > $text = &TWiki::handleCommonTags( $text, $topic ); > > # Send mail > my $error = &TWiki::Net::sendEmail( $text ); > > $url = &TWiki::getOopsUrl( $webName, $wikiName, "oopsresetpasswd", $emailsStr );