Problem with function "crypt"

M

madan

hi all,
i have a problem when using the function "crypt" in my code...

i want to encrypt a password when a user enters his password in the
textfield..

i wrote a simple code which will be called by itself and accept the
password..encrypt it and displays the ecrypted one and again asks for
another password..

Problem is that it is showing the same result for what ever text i
enter..i am using perl 5.6..

this code is working when tried in console(without CGI)...but when used
CGI i get the error...

the code is as below...
***********************************************************************************
#! c:\perl\bin\perl
use strict;
use CGI;
use CGI::Carp 'fatalsToBrowser';

my($cgi,$element,%passlist,$encrypted_password,$password);
$cgi=CGI->new;

print $cgi->header;
print $cgi->start_html;

foreach $element ($cgi->param)
{
$passlist{$element} = $cgi->param($element);
}

print "<form action=\"/cgi-bin/sample/encrypt.pl\">";

if($passlist{'gave'})
{
($encrypted_password) = &encrypt_text($password);
print "<br>the password you entered has been encrypted to
:$encrypted_password";
}

print "<br>Enter your password";
print "<br><input type=text name=\"pword\">";
print "<br><input type=submit value=\"Submit\">";
print "<input type=hidden name=\"gave\" value=\"true\">";

sub encrypt_text
{
my($text)=(@_);
my ($test,$encrypted_text);
$test = length($text).$text;
$text = length($text).$text;
$encrypted_text = crypt($text,$test);
return $encrypted_text;
}
****************************************************************************
thanks in advance
with regards
madan
 
M

mgarrish

madan said:
hi all,
i have a problem when using the function "crypt" in my code...
Problem is that it is showing the same result for what ever text i
enter..i am using perl 5.6..


use strict;

use warnings;
use CGI::Carp qw/fatalsToBrowser/;

The above lines would have tipped you off to the uninitialized value
warnings.
use CGI;
use CGI::Carp 'fatalsToBrowser';

my($cgi,$element,%passlist,$encrypted_password,$password);

You declare $password here, but then you never assign anything to it in
the following lines of code.
$cgi=CGI->new;

print $cgi->header;
print $cgi->start_html;

foreach $element ($cgi->param)
{
$passlist{$element} = $cgi->param($element);
}

print "<form action=\"/cgi-bin/sample/encrypt.pl\">";

if($passlist{'gave'})
{
($encrypted_password) = &encrypt_text($password);

And now you call encrypt_text every time with an undefined value, so
it's not surprising that you always get the same encrypted value back
(and the sub call doesn't need the special feature that appending an
'&' in front of it results in, so you shouldn't use one).

Matt
 
D

Dr.Ruud

(e-mail address removed) schreef:
madan:

use warnings;
use CGI::Carp qw/fatalsToBrowser/;

Maybe applies here too:

<quote>
Often overlooked, the warningsToBrowser call must be invoked too or
the buffer won't be flushed, eg,

use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
print header();
warningsToBrowser(1);
</quote>
 
M

mgarrish

Dr.Ruud said:
(e-mail address removed) schreef:

Maybe applies here too:

<quote>
Often overlooked, the warningsToBrowser call must be invoked too or
the buffer won't be flushed, eg,

use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
print header();
warningsToBrowser(1);
</quote>

Yes, and a particularly bad oversight on my part since he'd already put
the fatalsToBrowser call in and that's what I was responding to... : (

Matt
 
M

madan

thanks all for ur reply and support....the main thing i did wrong is
that i never used $password...i have to place the parameter as an
argument that was passed to the script in the calling function...now i
am getting unique encrypted values for the password i entered....
thanks again

with regards
madan chowdary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top