package Gruntmaster::Page::Passwd;

use 5.014000;
use strict;
use warnings;
use Gruntmaster::Page::Base;
our @ISA = qw/Gruntmaster::Page::Base/;
our $VERSION = '0.001';

use Apache2::Authen::Passphrase qw/pwcheck pwset/;
use Plack::Request;

sub generate{
	my ($self, $format, $env) = @_;
	my $r = Plack::Request->new($env);
	my ($oldpass, $newpass, $confirm) = map {scalar $r->param($_)} 'password', 'new_password', 'confirm_new_password';

	return reply 'Incorrect password' unless eval { pwcheck $r->user, $oldpass; 1 };
	return reply 'The two passwords do not match' unless $newpass eq $confirm;

	pwset $r->user, $newpass;
	reply 'Password changed successfully';
}

1
