--- bin/register	27 Apr 2003 09:03:42 -0000	1.37
+++ bin/register	23 Jun 2003 09:46:17 -0000
@@ -28,13 +28,7 @@
 use TWiki;
 use TWiki::Net;
 use TWiki::Plugins;
-
-if( $TWiki::OS eq "WINDOWS" ) {
-    require MIME::Base64;
-    import MIME::Base64 qw( encode_base64 );
-    require Digest::SHA1;
-    import Digest::SHA1 qw( sha1 );
-}
+use TWiki::Htpasswd;
 
 &main();
 
@@ -94,7 +88,7 @@
     # check if user entry already exists
     if(  ( $wikiName ) 
       && (  ( &TWiki::Store::topicExists( $webName,  $wikiName ) )
-         || ( htpasswdExistUser( $wikiName ) ) 
+         || ( &TWiki::Htpasswd::findEntry( $wikiName ) ) 
          ) ) {
         # PTh 20 Jun 2000: changed to getOopsUrl
         $url = &TWiki::getOopsUrl( $webName, $topic, "oopsregexist", $wikiName );
@@ -142,7 +136,9 @@
 
     # generate user entry and add to .htpasswd file
     if( ! $remoteUser ) {
-        htpasswdAddUser( htpasswdGeneratePasswd( $wikiName, $passwordA ) );
+    	my $newEntry = &TWiki::Htpasswd::makeEntry( $wikiName,
+    	    &TWiki::Htpasswd::encodePassword( $wikiName, $passwordA ) );
+        &TWiki::Htpasswd::addEntry( $newEntry );
     }
 
     # send email confirmation
@@ -223,6 +219,7 @@
     TWiki::redirect( $query, $url );
 }
 
+# pvgoran: this function is no longer needed.
 sub htpasswdGeneratePasswd
 {
     my ( $user, $passwd ) = @_;
@@ -246,6 +243,7 @@
     return "$user\:$passwdcrypt";
 }
 
+# pvgoran: this function is no longer needed.
 sub htpasswdExistUser
 {
     my ( $user ) = @_;
@@ -262,6 +260,7 @@
     return "";
 }
 
+# pvgoran: this function is no longer needed.
 sub htpasswdAddUser
 {
     my ( $userEntry ) = @_;
@@ -274,6 +273,7 @@
     &TWiki::Store::saveFile( $TWiki::htpasswdFilename, $text );
 }
 
+# pvgoran: this function is no longer needed.
 sub addUserToTWikiUsersTopic
 {
     my ( $wikiName, $remoteUser ) = @_;
--- bin/passwd	5 Jan 2003 02:38:11 -0000	1.11
+++ bin/passwd	23 Jun 2003 09:49:51 -0000
@@ -47,6 +47,7 @@
 use CGI::Carp qw(fatalsToBrowser);
 use CGI;
 use TWiki;
+use TWiki::Htpasswd;
 
 if( $TWiki::OS eq "WINDOWS" ) {
     require MIME::Base64;
@@ -83,8 +84,9 @@
         return;
     }
  
-    # check if user entry exists
-    if(  ( $wikiName )  && (! htpasswdExistUser( $wikiName ) ) ) {
+    # find user entry, display the warning if it doesn't exist
+    my $oldEntry = &TWiki::Htpasswd::findEntry( $wikiName );
+    if( ! $oldEntry ) {
         # PTh 20 Jun 2000: changed to getOopsUrl
         $url = &TWiki::getOopsUrl( $webName, $topic, "oopsnotwikiuser", $wikiName );
         TWiki::redirect( $query, $url );
@@ -98,7 +100,11 @@
         return;
     }
 
-    my $theCryptPassword = &htpasswdGeneratePasswd( $wikiName,  $passwordA );
+    # generate the new encrypted password and the password entry
+    my $newEncryptedPassword = 
+    	&TWiki::Htpasswd::encodePassword( $wikiName, $passwordA );
+   	my $newEntry = 
+   		&TWiki::Htpasswd::makeEntry( $wikiName, $newEncryptedPassword );
  
     my $change = $query->param( "change" ) || "";
  
@@ -115,10 +121,7 @@
         }
 
         # check password
-        my $oldcrypt = htpasswdReadPasswd( $wikiName );
- 
-        my $pw = htpasswdCheckPasswd( $oldpassword, $oldcrypt );
-        if( ! $pw ) {
+        if( ! &TWiki::Htpasswd::verifyPassword( $oldEntry, $oldpassword ) ) {
             # NO - wrong old password
             $url = &TWiki::getOopsUrl( $webName, $topic, "oopswrongpassword");
             TWiki::redirect( $query, $url );
@@ -126,8 +129,7 @@
         }
  
         # OK - password may be changed
-        my $oldCryptPassword = "$wikiName\:$oldcrypt";
-        htpasswdAddUser( $oldCryptPassword, $theCryptPassword );
+        &TWiki::Htpasswd::replaceEntry( $oldEntry, $newEntry );
  
         # OK - password changed
         $url = &TWiki::getOopsUrl( $webName, $topic, "oopschangepasswd" );
@@ -138,13 +140,16 @@
  
         # r e s e t
         # and finally display the reset password page
-        $url = &TWiki::getOopsUrl( $webName, $wikiName, "oopsresetpasswd", $theCryptPassword );
+        $url = &TWiki::getOopsUrl( 
+        	$webName, $wikiName, "oopsresetpasswd", 
+        	"$wikiName:$newEncryptedPassword" );
         TWiki::redirect( $query, $url );
         return;
     }
  
 }
  
+# pvgoran: this function is no longer needed.
 # =========================
 sub htpasswdCheckPasswd
 {
@@ -171,6 +176,7 @@
     return "";
 }
  
+# pvgoran: this function is no longer needed.
 # =========================
 sub htpasswdReadPasswd
 {
@@ -187,6 +193,7 @@
     return "";
 }
  
+# pvgoran: this function is no longer needed.
 # =========================
 sub htpasswdExistUser
 {
@@ -203,6 +210,7 @@
     return "";
 }
  
+# pvgoran: this function is no longer needed.
 # =========================
 sub htpasswdGeneratePasswd
 {
@@ -225,6 +233,7 @@
     return "$user\:$passwdcrypt";
 }
  
+# pvgoran: this function is no longer needed.
 # =========================
 sub htpasswdAddUser
 {
--- bin/installpasswd	5 Jan 2003 01:46:45 -0000	1.8
+++ bin/installpasswd	23 Jun 2003 09:52:07 -0000
@@ -39,6 +39,7 @@
 use CGI::Carp qw(fatalsToBrowser);
 use CGI;
 use TWiki;
+use TWiki::Htpasswd;
  
 $query= new CGI;
  
@@ -79,11 +80,13 @@
         TWiki::redirect( $query, $url );
         return;
     }
+
+    my ( $installWikiName, $installEncryptedPassword );
 	
     # TODO: I18N fix here once basic auth problem with 8-bit user names is
     # solved
-    if ( $theCryptPassword =~ m/^([A-Z][a-zA-Z]+[A-Z][a-zA-Z]*)\:.{13}$/ ) {
-	$wikiName = $1;
+    if ( $theCryptPassword =~ m/^([A-Z][a-zA-Z]+[A-Z][a-zA-Z]*)\:(.*)$/ ) {
+		( $installWikiName, $installEncryptedPassword ) = ( $1, $2 );
     } else {
 	# bad format
     	$url = &TWiki::getOopsUrl( $webName, $topic, "oopsbadpwformat", $theCryptPassword);
@@ -91,19 +94,18 @@
         return;
     }
 
-    # check if user entry exists
-    if(  ( $wikiName )  && (! htpasswdExistUser( $wikiName ) ) ){
+    # find user entry, display the warning if it doesn't exist
+    my $oldEntry = &TWiki::Htpasswd::findEntry( $installWikiName );
+    if( !$oldEntry ){
         # PTh 20 Jun 2000: changed to getOopsUrl
         $url = &TWiki::getOopsUrl( $webName, $topic, "oopsnotwikiuser", $wikiName );
         TWiki::redirect( $query, $url );
         return;
     }
 
-    # old password
-    my $oldcrypt = htpasswdReadPasswd( $wikiName );
-    # OK - password may be changed
-    my $oldCryptPassword = "$wikiName\:$oldcrypt";
-    htpasswdAddUser( $oldCryptPassword, $theCryptPassword );
+    my $newEntry = &TWiki::Htpasswd::makeEntry(
+    	$installWikiName, $installEncryptedPassword );
+	&TWiki::Htpasswd::replaceEntry( $oldEntry, $newEntry );
 
     # OK - password changed
     $url = &TWiki::getOopsUrl( $webName, $topic, "oopschangepasswd" );
@@ -112,6 +114,7 @@
 }
 
 #========================= 
+# pvgoran: this function is no longer needed.
 sub htpasswdReadPasswd
 {
     my ( $user ) = @_;
@@ -127,6 +130,7 @@
     return "";
 }
  
+# pvgoran: this function is no longer needed.
 sub htpasswdExistUser
 {
     my ( $user ) = @_;
@@ -142,6 +146,7 @@
     return "";
 }
  
+# pvgoran: this function is no longer needed.
 sub htpasswdAddUser
 {
     my ( $oldUserEntry, $newUserEntry ) = @_;
--- bin/.htaccess.txt	11 Apr 2003 05:59:12 -0000	1.11
+++ bin/.htaccess.txt	23 Jun 2003 12:28:32 -0000
@@ -8,13 +8,21 @@
 # if your web hosting provider permits this.  Remove if using mod_perl.
 SetHandler cgi-script
 
+# Authentication type
+AuthType Basic
+#AuthType Digest
+#AuthDigestDomain /urlpath/to/twiki/bin/viewauth /urlpath/to/twiki/bin/edit /urlpath/to/twiki/bin/preview /urlpath/to/twiki/bin/save /urlpath/to/twiki/bin/attach /urlpath/to/twiki/bin/upload /urlpath/to/twiki/bin/rename /urlpath/to/twiki/bin/manage /urlpath/to/twiki/bin/installpasswd /urlpath/to/twiki/bin/passwd
+
 # Password file for TWiki users
 #
 # The path here must be a system file pathname, not a URL - first part should 
 # match the $dataDir setting in TWiki.cfg
 AuthUserFile /filepath/to/TWiki/data/.htpasswd
-AuthName 'Enter your WikiName: (First name and last name, no space, no dots, capitalized, e.g. JohnSmith). Cancel to register if you do not have one.'
-AuthType Basic
+#AuthDigestFile /filepath/to/TWiki/data/.htdigest
+
+# For "Digest" authentication to work properly, this string must match
+# the value of configuration variable $authRealm
+AuthName 'Enter your WikiName. (First name and last name, no space, no dots, capitalized, e.g. JohnSmith). Cancel to register if you do not have one.'
 
 # File to return on access control error (e.g. wrong password)
 # The path here must be a URL path, not a file pathname - first part should 
--- lib/TWiki.cfg	30 May 2003 19:06:29 -0000	1.57
+++ lib/TWiki.cfg	28 Jun 2003 20:03:52 -0000
@@ -317,6 +317,14 @@
 $warningFilename    = "$logDir/warning.txt";
 #                   Pathname of user name/password file for authentication :
 $htpasswdFilename   = "$dataDir/.htpasswd";
+#$htpasswdFilename   = "$dataDir/.htdigest";
+#                   pvgoran: Password file format/generation method :
+#                   htpasswd:plain, htpasswd:crypt, htpasswd:md5 (currently unsupported),
+#                   htpasswd:sha1, htdigest:md5
+$htpasswdFormat     = "htpasswd:crypt";
+#                   pvgoran: authentication "realm" (must be the same as in
+#                   password file, MUST NOT contain colons):
+$authRealm          = "Enter your WikiName. (First name and last name, no space, no dots, capitalized, e.g. JohnSmith). Cancel to register if you do not have one.";
 #                   Pathname of log file :
 $logFilename        = "$logDir/log%DATE%.txt";
 #                   Pathname of remote users file that maps IP to user :
