mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-28 11:43:25 +02:00
BUG10963: implement a better email verification
We now check all allowed chars in the address before the @ sign. The domainpart after the '@' sign is just checked for valid chars, so that user@ipfire is valid, too Signed-off-by: Alexander Marx <alexander.marx@ipfire.org> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
committed by
Michael Tremer
parent
915c88931a
commit
b00797e260
@@ -747,14 +747,25 @@ sub ipcidr2msk {
|
||||
}
|
||||
|
||||
sub validemail {
|
||||
my $mail = shift;
|
||||
return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
|
||||
return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
|
||||
return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
|
||||
return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
|
||||
return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
|
||||
return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
|
||||
return 0 if ( $mail !~ /\.([a-zA-Z]{2,4})$/ );
|
||||
my $address = shift;
|
||||
my @parts = split( /\@/, $address );
|
||||
my $count=@parts;
|
||||
|
||||
#check if we have one part before and after '@'
|
||||
return 0 if ( $count != 2 );
|
||||
|
||||
#check if one of the parts starts or ends with a dot
|
||||
return 0 if ( substr($parts[0],0,1) eq '.' );
|
||||
return 0 if ( substr($parts[0],-1,1) eq '.' );
|
||||
return 0 if ( substr($parts[1],0,1) eq '.' );
|
||||
return 0 if ( substr($parts[1],-1,1) eq '.' );
|
||||
|
||||
#check first addresspart (before '@' sign)
|
||||
return 0 if ( $parts[0] !~ m/^[a-zA-Z0-9\.!\-\+#]+$/ );
|
||||
|
||||
#check second addresspart (after '@' sign)
|
||||
return 0 if ( $parts[1] !~ m/^[a-zA-Z0-9\.\-]+$/ );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user