X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FAuth%2Finternal.pm;h=92dff03189e1b87ff70ef6fc7bff159bbe69ea60;hb=HEAD;hp=f6d1a008612ea09f5c13660f4d14ccaae61ac9ff;hpb=63973c641c4be00765fa27e55c57cc5b9aa4da19;p=freeside.git diff --git a/FS/FS/Auth/internal.pm b/FS/FS/Auth/internal.pm index f6d1a0086..92dff0318 100644 --- a/FS/FS/Auth/internal.pm +++ b/FS/FS/Auth/internal.pm @@ -7,7 +7,7 @@ use FS::Record qw( qsearchs ); use FS::access_user; sub authenticate { - my($self, $username, $check_password ) = @_; + my($self, $username, $check_password, $totp_code ) = @_; my $access_user = ref($username) ? $username @@ -17,6 +17,7 @@ sub authenticate { ) or return 0; + my $pw_check; if ( $access_user->_password_encoding eq 'bcrypt' ) { my( $cost, $salt, $hash ) = split(',', $access_user->_password); @@ -29,17 +30,21 @@ sub authenticate { ) ); - $hash eq $check_hash; + $pw_check = $hash eq $check_hash; - } else { + } else { return 0 if $access_user->_password eq 'notyet' || $access_user->_password eq ''; - $access_user->_password eq $check_password; + $pw_check = $access_user->_password eq $check_password; } + return $pw_check if ! $pw_check || ! length($access_user->totp_secret32); + + #2fa + $access_user->google_auth->verify( $totp_code, 1 ); } sub autocreate { 0; } @@ -47,6 +52,11 @@ sub autocreate { 0; } sub change_password { my($self, $access_user, $new_password) = @_; + # do nothing if the password is unchanged + #XXX breaks password changes in employee edit ($access_user object already + # has new [plaintext] password) + #return if $self->authenticate( $access_user, $new_password ); + $self->change_password_fields( $access_user, $new_password ); $access_user->replace;