LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-31-2008, 03:46 AM   #1
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Rep: Reputation: 17
decrypt in perl


Hi guys.I have a question. Let me show my code.


Code:
#!/usr/bin/perl -w

use strict;


print "username\n";
my $name = <STDIN>;

print "password\n";
my $pass = <STDIN>;

my $paswd = crypt($pass,"password");

open(FILEHANDLE, ">fail.txt") or die "cannot open file:$!";

print FILEHANDLE "$name";
print FILEHANDLE "$paswd";
If i use

my $paswd = crypt($pass,"password");

now i want to read the fail.txt, but I wan to decrypt, so that I can see the password. How to do the decryption.

Please help
 
Old 03-31-2008, 05:37 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
Passwords don't work that way. To authenticate, you accept a plaintext password and encrypt (hash) it in the same manner. Then compare the two.
 
Old 03-31-2008, 09:13 AM   #3
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Original Poster
Rep: Reputation: 17
What if i want to encrypt the username only..just for fun..how am i goin to decrypt it back
 
Old 03-31-2008, 03:09 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 69
Quote:
Originally Posted by john83reuben View Post
how am i goin to decrypt it back
You aren’t (unless you use brute force). The name “crypt” is misleading as the actual function gives you a salted cryptographic hash of the input. If you want to do cryptography, use the Crypt::* perl modules.
 
Old 03-31-2008, 08:26 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,225

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
You ought to chomp() your inputs as well, to remove the trailing '\n'.
 
Old 03-31-2008, 09:59 PM   #6
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,231

Rep: Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071
This question really deserves some research on your part... and in the Perl world that basically means CPAN: http://www.cpan.org

Let's face it: you are not the first person on the planet to have needed a good way to "solve the validation and/or authentication problem" in an application. Others have solved the problem in hundreds of ways before you, and they've put a boatload of well-tested solutions into CPAN.

Don't reinvent... anything. Ever.
Quote:
Dictum Ne Agas: Do Not Do A Thing Already Done.
Instead of banging your head against this trivial problem "yet again," search for an existing module that you can install and use.

Your time is much better-spent on the concerns that make your application unique, not the routine concerns that are identical for every application in the universe.

And mind you, I do not mean this as a "slam." It is hard to train yourself to think this way, and you very-easily forget. Me, too. Mea culpa. Just last week I was sorta-showin'-off a little-clever-thing I'd sorta-come-up with ... and he casually mentioned a CPAN module that I coulda-sorta-just USED and he gave me this good-natured slight-smile and ... ... well, it kinda-sorta keeps ya in your place until you can sneak out by the water cooler and say "Doh!!!"

Last edited by sundialsvcs; 03-31-2008 at 10:04 PM.
 
Old 04-01-2008, 03:12 AM   #7
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Original Poster
Rep: Reputation: 17
hii..I solved the problem already. I used CPAN like you guys said. THanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't decrypt anything with GPG Jorophose Linux - Security 2 12-06-2007 04:57 PM
Decrypt SSL ajaye1971 Linux - Security 1 08-30-2006 04:06 PM
Kremlyn Decrypt? Alexo Linux - Software 1 05-24-2005 10:25 PM
Need help to decrypt error messages jfi Mandriva 1 03-09-2004 11:30 AM
decrypt pdf Daniel Han Linux - General 8 01-27-2004 03:34 AM


All times are GMT -5. The time now is 01:22 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration