+sub register{
+ my $r = shift;
+ my $req = Apache2::Request->new($r);
+ my ($username, $password, $confirm_password, $name, $email, $town, $university) = map {scalar $req->param($_)} 'username', 'password', 'confirm_password', 'name', 'email', 'town', 'university';
+
+ local $Apache2::Authen::Passphrase::rootdir = $r->dir_config('AuthenPassphraseRootdir');
+ return aputs $r, 'Bad username. Allowed characters are letters, digits and underscores, and the username must be between 2 and 20 characters long.' unless $username =~ USER_REGEX;
+ return aputs $r, 'Username already in use' if -e "$Apache2::Authen::Passphrase::rootdir/$username.yml";
+ return aputs $r, 'The two passwords do not match' unless $password eq $confirm_password;
+ pwset $username, $password;
+
+ insert_user $username, name => $name, email => $email, town => $town, university => $university;
+
+ aputs $r, 'Registered successfully';
+}
+
+sub passwd{
+ my $r = shift;
+ my $req = Apache2::Request->new($r);
+ my ($oldpass, $newpass, $confirm) = map {scalar $req->param($_)} 'password', 'new_password', 'confirm_new_password';
+
+ local $Apache2::Authen::Passphrase::rootdir = $r->dir_config('AuthenPassphraseRootdir');
+ return aputs $r, 'Incorrect password' unless eval { pwcheck $r->user, $oldpass; 1 };
+ return aputs $r, 'The two passwords do not match' unless $newpass eq $confirm;
+
+ pwset $r->user, $newpass;
+ aputs $r, 'Password changed successfully';
+}
+