Changeset 2456


Ignore:
Timestamp:
03/05/21 16:32:33 (3 years ago)
Author:
nanardon
Message:

Ajout testpass à la-cli

Location:
trunk/LATMOS-Accounts/lib/LATMOS/Accounts
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm

    r2441 r2456  
    12081208    }; 
    12091209 
    1210     if ($uobj->_get_c_field('expired')) { 
    1211         la_log(LA_ERR, "Account $username has expired (%s)", 
    1212             $uobj->_get_c_field('expired')); 
    1213         return; 
    1214     } 
    1215  
    1216     if ($uobj->_get_c_field('locked')) { 
    1217         la_log(LA_ERR, "Account $username is currently locked"); 
    1218         return; 
    1219     } 
    1220  
    1221     my $password = $uobj->get_field('userPassword') or do { 
    1222         la_log(LA_ERR, "Cannot authenticate user $username having no passwd"); 
    1223         return; 
    1224     }; 
    1225     if ($password eq crypt($passwd, $password)) { # crypt unix 
    1226         la_log(LA_NOTICE, "User $username authenticated"); 
    1227         return 1; 
    1228     } else { 
    1229         la_log(LA_ERR, "Cannot authenticate user $username: wrong password"); 
    1230         return 0; 
    1231     } 
     1210    $uobj->Authenticate( $passwd ); 
    12321211} 
    12331212 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm

    r2433 r2456  
    22002200} 
    22012201 
     2202=head2 CheckAccountValidity 
     2203 
     2204Check account is still valid. 
     2205 
     2206=cut 
     2207 
     2208sub CheckAccountValidity { 
     2209    my ( $self ) = @_; 
     2210 
     2211    my $username = $self->id; 
     2212 
     2213    if ($self->_get_c_field('unexported')) { 
     2214        la_log(LA_ERR, "Account $username is unexported"); 
     2215        return; 
     2216    } 
     2217 
     2218    if ($self->_get_c_field('expired')) { 
     2219        la_log(LA_ERR, "Account $username has expired (%s)", 
     2220            $self->_get_c_field('expired')); 
     2221        return; 
     2222    } 
     2223 
     2224    if ($self->_get_c_field('locked')) { 
     2225        la_log(LA_ERR, "Account $username is currently locked"); 
     2226        return; 
     2227    } 
     2228 
     2229    1; 
     2230} 
     2231 
     2232=head2 ComparePassword ($password) 
     2233 
     2234Check the password is the current one 
     2235 
     2236=cut 
     2237 
     2238sub ComparePassword { 
     2239    my ( $self, $passwd ) = @_; 
     2240 
     2241    my $username = $self->id; 
     2242 
     2243    my $password = $self->get_field('userPassword') or do { 
     2244        la_log(LA_ERR, "Cannot authenticate user $username having no passwd"); 
     2245        return; 
     2246    }; 
     2247    if ($password eq crypt($passwd, $password)) { # crypt unix 
     2248        la_log(LA_NOTICE, "User $username authenticated"); 
     2249        return 1; 
     2250    } else { 
     2251        la_log(LA_ERR, "Cannot authenticate user $username: wrong password"); 
     2252        return 0; 
     2253    } 
     2254} 
     2255 
     2256 
     2257=head2 Authenticate( $password ) 
     2258 
     2259Authenticate the user 
     2260 
     2261=cut 
     2262 
     2263sub Authenticate { 
     2264    my ( $self, $password ) = @_; 
     2265 
     2266    $self->CheckAccountValidity or return; 
     2267 
     2268    $self->ComparePassword( $password ); 
     2269} 
     2270 
    22022271=head2 storeBannedPassword($epassword) 
    22032272 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli.pm

    r2438 r2456  
    232232            }, 
    233233        }); 
     234=head2 testpass 
     235 
     236=cut 
     237 
     238    $self->add_func('testpass', { 
     239            help => 'Test password for given user', 
     240            completion => sub { 
     241                if (! $_[2]) { 
     242                    return $_[0]->base->list_objects('user'); 
     243                } 
     244            }, 
     245            code => sub { 
     246                my ($self, $user, @passwd) = @_; 
     247                my $uobj = $self->base->get_object('user', $user) or do { 
     248                    $self->print("Cannot get user $user\n"); 
     249                    return; 
     250                }; 
     251 
     252                if (! $uobj->CheckAccountValidity ) { 
     253                    $self->print("Account $user cannot currently log\n"); 
     254                } 
     255 
     256                foreach (@passwd) { 
     257                    my $is = $uobj->ComparePassword( $_ ); 
     258                    if ($is) { 
     259                        $self->print("Passord for $user is $_\n"); 
     260                        last; 
     261                    } 
     262                } 
     263            }, 
     264        }); 
    234265 
    235266=head3 create 
Note: See TracChangeset for help on using the changeset viewer.