Hi
Can anyone help me with a script that I have made?
It is a script who are going to add users to a passwd file.
It works fine when I add one user at the time but when I add more than
one user the usernumber start to count higher for every user.
I want it to count like this:
-----------
SLCT1000
SLCT1001
SLCT1002
etc...
but it count
-------------
SLCT1000
SLCT1002
SLCT1005
SLCT1011
etc..
can anyone help me out?
newhtpasswd is a program who creates a htpasswd like user and
randompasswd is a program who generates a randm password.
Here is the code.
-------------
#!/usr/bin/perl
$newpass = "newhtpasswd";
$random = "randompasswd";
$base = 1000;
$prefix = "SLCT";
$lenght = 8;
$passwdfile = "test";
$kundlista = "lista.txt";
print "How many passwords do you want to create? ";
chomp ($antal = <STDIN>);
while ($antal > 0) {
log_pass();
to_file();
$antal--;
}
sub log_pass {
@pwfile = `cat $passwdfile';
$size = @pwfile;
$logname = "raven";
$base += $size;
while ('grep $logname $passwdfile') {
$base++;
$logname = "${prefix}${base}";
}
$passwd = '$random $lenght';
system ("$newpass $passwdfile $logname $passwd");
}
sub to_file {
$filedate = 'date +%Y%m%d';
open (FILE, ">>$kundlista") || die "can't open file";
print FILE "--------------------\n";
print FILE "Regdate: $filedate";
print FILE "Login: $logname\n";
print FILE "Password: $passwd\n";
close (FILE) || die "can not close file";
}