+ my $ret=0;
+ if (exists $userinfo->{$user}->{"crypt".$field}) {
+ eval q{use Authen::Passphrase};
+ error $@ if $@;
+ my $p = Authen::Passphrase->from_crypt($userinfo->{$user}->{"crypt".$field});
+ $ret=$p->match($password);
+ }
+ elsif (exists $userinfo->{$user}->{$field}) {
+ $ret=$password eq $userinfo->{$user}->{$field};
+ }
+
+ if ($ret &&
+ (exists $userinfo->{$user}->{resettoken} ||
+ exists $userinfo->{$user}->{cryptresettoken})) {
+ # Clear reset token since the user has successfully logged in.
+ delete $userinfo->{$user}->{resettoken};
+ delete $userinfo->{$user}->{cryptresettoken};
+ IkiWiki::userinfo_store($userinfo);
+ }
+
+ return $ret;
+}
+
+sub setpassword ($$;$) {
+ my $user=shift;
+ my $password=shift;
+ my $field=shift || "password";
+
+ eval q{use Authen::Passphrase::BlowfishCrypt};
+ if (! $@) {
+ my $p = Authen::Passphrase::BlowfishCrypt->new(
+ cost => $config{password_cost} || 8,
+ salt_random => 1,
+ passphrase => $password,
+ );
+ IkiWiki::userinfo_set($user, "crypt$field", $p->as_crypt);
+ IkiWiki::userinfo_set($user, $field, "");
+ }
+ else {
+ IkiWiki::userinfo_set($user, $field, $password);
+ }
+}
+
+sub formbuilder_setup (@) {