CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Encrypt a password

 



GhostNr1
Deleted

Jun 6, 2001, 7:16 AM

Post #1 of 5 (1323 views)
Encrypt a password Can't Post

I need a encryption algoritm that I can use when I should put me password in a file.
Then when I should login I must encrypt the password and compare the password from the file. Any ide?
I have all exept from the encryption thing!



wickedxter
User

Jun 6, 2001, 7:50 AM

Post #2 of 5 (1322 views)
Re: Encrypt a password [In reply to] Can't Post

just make one up.. it's not hard to encyrpt things

$string =~ s/A/what ever you want letter a to be/g;

then you just do it the other way around to decrypt it

$string =~ s/what ever letter equals/A/g;

thats what i use to encyrpt things..



GhostNr1
Deleted

Jun 6, 2001, 10:10 AM

Post #3 of 5 (1318 views)
Re: Encrypt a password [In reply to] Can't Post

So I must do that to all the letters?
But if I whant a -> c and c ->e and e -> a then I have a big problem!
Isn't there any easyer way?
Or have I missunderstand something?



rGeoffrey
User

Jun 7, 2001, 2:19 PM

Post #4 of 5 (1307 views)
Re: Encrypt a password [In reply to] Can't Post

If you need to be able to undo the encryption you could do something like this...


Code
my $string = "Four score and seven years ago..."; 

print $string, "\n";
$string =~ tr/a-zA-Z/n-za-mN-ZA-M/;
print $string, "\n";
$string =~ tr/a-zA-Z/n-za-mN-ZA-M/;
print $string, "\n";

This a a ROT13 encryption where every letter is rotated 13 positions in the alphabet. So the same method again will bring it back. But you are probably better off using a more complicated substitution, just make sure that all 26 letters are replaced with all 26 letters.

If you just need to be able to verify that the password matches the encrypted one on file you can use crypt...


Code
my $password = 'bedrock'; 
my $salt = 'qN'; #some 'random' two characters

my $encrypted = crypt ($password, $salt);

if ($encrypted eq crypt ($password, $encrypted)) {
print "welcome back\n";
} else {
print "your password does not match\n";
}

crypt will use the "salt" to decide how to do the encryption and will take your password of upto 8 significant characters and return one of 13 characters where the first two are the salt. So then you just encrypt their guess of a password using the one on file as the salt. If that matches the one on file then they are who they say they are.

If you need heavy duty security you should look into something stronger, but these two methods should at least force the bad guys to do a little thinking and not just walk in because you forgot to lock the door.

--
Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?


Zephyr
Deleted

Jun 9, 2001, 1:08 PM

Post #5 of 5 (1293 views)
Re: Encrypt a password [In reply to] Can't Post

Try the Crypt-RC4-1.11 module on the Cpan site. I have used this
successfully and it should do the job easily...

Let me know how it goes....

Zephyr


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives