1 package FS::ClientAPI::passwd;
4 use FS::Record qw(qsearchs);
8 use FS::ClientAPI; #hmm
9 FS::ClientAPI->register_handlers(
10 'passwd/passwd' => \&passwd,
11 'passwd/chfn' => \&chfn,
12 'passwd/chsh' => \&chsh,
18 my $domain = $FS::ClientAPI::domain || $packet->{'domain'};
19 my $svc_domain = qsearchs('svc_domain', { 'domain' => $domain } )
20 or return { error => "Domain $domain not found" };
22 my $old_password = $packet->{'old_password'};
23 my $new_password = $packet->{'new_password'};
24 my $new_gecos = $packet->{'new_gecos'};
25 my $new_shell = $packet->{'new_shell'};
27 #false laziness w/FS::ClientAPI::MyAccount::login (needs to handle encrypted pw)
29 ( length($old_password) < 13
30 && qsearchs( 'svc_acct', { 'username' => $packet->{'username'},
31 'domsvc' => $svc_domain->svcnum,
32 '_password' => $old_password } )
34 || qsearchs( 'svc_acct', { 'username' => $packet->{'username'},
35 'domsvc' => $svc_domain->svcnum,
36 '_password' => $old_password } );
38 unless ( $svc_acct ) { return { error => 'Incorrect password.' } }
40 my %hash = $svc_acct->hash;
41 my $new_svc_acct = new FS::svc_acct ( \%hash );
42 $new_svc_acct->setfield('_password', $new_password )
43 if $new_password && $new_password ne $old_password;
44 $new_svc_acct->setfield('finger',$new_gecos) if $new_gecos;
45 $new_svc_acct->setfield('shell',$new_shell) if $new_shell;
46 my $error = $new_svc_acct->replace($svc_acct);
48 return { error => $error };