Sky as a Kite

Main menu

a log in

I finally wrote a log in and log out script for the blog.
I was trying to go for simplistic, but secure and without the need to install more modules (as this would have put me off from using the blog when I first started my internet presence...)

so here is my script:
my $cookie=cookie('admin');

my $form_pass = r('password');
my $value = crypt(rand(999999), $config_randomString);

if (r('do')eq 'log_out'){
unlink "$config_commentsDatabaseFolder/log_in.txt";
$cookie = cookie(-name=>'admin', value=>'log out', expires=>'-1d');
$cookie->bake;
print "<br />You have logged out. Goodbye!";
}

if (r('process')eq 'log_in'){
if ($form_pass eq $config_adminPass){
open FILE, "+>$config_commentsDatabaseFolder/log_in.txt";
print FILE $value;
close FILE;
$cookie = cookie( -name => 'admin',
-value => $value );
$cookie->bake;
print "<br />You are logged in. Welcome!";
}
else { print '<br />Wrong password!';}
}
open FILE, "$config_commentsDatabaseFolder/log_in.txt";
while (<FILE>){$value = $_ ;}
close FILE;

unless ($cookie eq $value || $form_pass eq $config_adminPass){
print '<form method="post">
<h1>Type in your password:</h1><br />
<input type="text" name="password">
<input name="process" type="hidden" id="process" value="log_in">
<input type="submit" name="Submit" type="hidden" value="log in"></form>';
exit;
}


I really don't know if this is a good way of doing this, comments are very much welcome, but be gentle!
Posted on - Categories: Geekery


No comments posted yet

Add Comment