# [PATCH 4/5] git-cvsserver: break the loop after successful hit

2 messages from 2010-07-06 to 2010-07-07. Participants: Áshin László, Junio C Hamano.
Thread: https://gitlist.dev/t/24305

## Áshin László, 2010-07-06 17:38

Subject: [PATCH 4/5] git-cvsserver: break the loop after successful hit
Message-ID: <AANLkTik0pMkYDHZD9jgzn3OaGUdyeiFwAv7o3OTUmEvO@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTik0pMkYDHZD9jgzn3OaGUdyeiFwAv7o3OTUmEvO%40mail.gmail.com
In-Reply-To: <-1324832183078898154@unknownmsgid>

```
No need to check for more lines of the authentication database after found a
matching one.
---
 git-cvsserver.perl |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index e842d77..cd461ac 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -248,11 +248,10 @@ if ($state->{method} eq 'pserver') {
        my $auth_ok;
        open my $passwd, "<", $authdb or die $!;
        while (<$passwd>) {
-            if (m{^\Q$user\E:(.*)}) {
-                if (crypt($user, $password) eq $1) {
-                    $auth_ok = 1;
-                }
-            };
+            if (m{^\Q$user\E:(.*)} && crypt($user, $password) eq $1) {
+                $auth_ok = 1;
+                last;
+            }
        }
        close $passwd;

--
1.7.0.4

```

## Junio C Hamano, 2010-07-07 05:28

Subject: Re: [PATCH 4/5] git-cvsserver: break the loop after successful hit
Message-ID: <7vwrt7zwqe.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vwrt7zwqe.fsf%40alter.siamese.dyndns.org
In-Reply-To: <AANLkTik0pMkYDHZD9jgzn3OaGUdyeiFwAv7o3OTUmEvO@mail.gmail.com>

```
Áshin László <ashinlaszlo@gmail.com> writes:

> No need to check for more lines of the authentication database after found a
> matching one.

s/found/finding/;

But I see a bigger issue here.  Is it plausible that you might want to
allow two entries for one user, with two different passwords, in an authdb
file?  The current code allows it, but if we want to disallow it, we could
instead add your "last", like this, if you do not break the structure of
the conditional statements in the original code.

	while (<$passwd>) {
		if (m{^\Q$user\E:(.*)}) {
			if (crypt($user, $password) eq $1) {
				$auth_ok = 1;
			}
			last;
		}
	}

Or have the "last" inside the inner "if" statement to keep that logic.

Either way I think the original nested "if" is much easier to read than
your version.

```
