+sub reset_passwd {
+ my $p = shift;
+
+ my $conf = new FS::Conf;
+ my $verification = $conf->config('selfservice-password_reset_verification')
+ or return { 'error' => 'Password resets disabled' };
+
+ my $username = $p->{'username'};
+
+ my $svc_domain = qsearchs('svc_domain', { 'domain' => $p->{'domain'} } )
+ or return { 'error' => 'Account not found' };
+
+ my $svc_acct = qsearchs('svc_acct', { 'username' => $p->{'username'},
+ 'domsvc' => $svc_domain->svcnum }
+ )
+ or return { 'error' => 'Account not found' };
+
+ my $cust_pkg = $svc_acct->cust_svc->cust_pkg
+ or return { 'error' => 'Account not found' };
+
+ my $cust_main = $cust_pkg->cust_main;
+
+ my %verify = (
+ 'paymask' => sub {
+ my( $p, $cust_main ) = @_;
+ $cust_main->payby =~ /^(CARD|DCRD|CHEK|DCHK)$/
+ && $p->{'paymask'} eq substr($cust_main->paymask, -4)
+ },
+ 'amount' => sub {
+ my( $p, $cust_main ) = @_;
+ my $cust_pay = qsearchs({
+ 'table' => 'cust_pay',
+ 'hashref' => { 'custnum' => $cust_main->custnum },
+ 'order_by' => 'ORDER BY _date DESC LIMIT 1',
+ })
+ or return 0;
+
+ $p->{'amount'} == $cust_pay->paid;
+ },
+ 'zip' => sub {
+ my( $p, $cust_main ) = @_;
+ $p->{'zip'} eq $cust_main->zip
+ || ( $cust_main->ship_zip && $p->{'zip'} eq $cust_main->ship_zip );
+ },
+ );
+
+ foreach my $verify ( split(',', $verification) ) {
+
+ &{ $verify{$verify} }( $p, $cust_main )
+ or return { 'error' => 'Account not found' };
+
+ }
+
+ #we're verified. now what?
+
+
+ return { 'error' => '' };
+}
+
+