I have a client and server application.MY client is sending the username(which it gets through getlogin()) to server.I want server to save all the registered username in a file called username.On receiving the request from client,it checks the username of client in the file and if it founds it ,its gives him permission to go ahead otherwise rejects it.
here is what i did:
<code>
$user = <$client_socket>;
chop($user);
unless (open (USERNAME, "username"))
{
print "ERROR:Cannot open username file.\n";
exit(1); # ERROR
}
while(<USERNAME>)
{
my @newusername = <USERNAME>;
foreach $name (@newusername)
{
if($name ne $user) {
print $client_socket "ERR\n";
print "$prefix ERROR: user $user not allowed. Exiting.\n";
close(USERNAME);
exit(1);
}
}
}
#else,
print $client_socket "ACK\n"; #got approved
close(USERNAME);
<\code>
this isnt working as even when the file username has client name it is giving "user $user not allowed".