John W. Krahn wrote:
PekinSOFT wrote:
John W. Krahn wrote:
pekins...@gmail.com wrote:
I enter the string 'hiyall2008' in the password field and get the
following values in my logon script...
Click 1: hiyall2008153639492
Click 2: hiyall2008135813700
Click 3: hiyall2008152312388
et cetera...
As you can see, there is a different arbitrary string of numbers at
the end of the clear text of the password entered. If it was the same
each time the password was entered, I would just make it a part of the
password and encrypt the whole thing into my database. However, each
time it is different. It appears to be only 9 numbers each time, so I
decided to try and strip those 9 numbers off the password with the
'substr()' method. So, I created the following sub procedure to do
that:
sub strip_string
{
my $ret = "";
for (my $i = 0; $i < length($_[0]) - 9; $i++) {
$ret .= substr(length($_[0]) - $i, 1);
Say that you pass the string "hiyall2008153639492" to strip_string
and the length of that string is 19 characters. At the start of the
loop $i is 0 and length($_[0]) - $i is 19 so your expression says:
$ret .= substr("19", 1);
Or:
$ret .= "9";
At the next iteration through the loop $i is 1 so you have:
$ret .= substr("18", 1);
#print $ret;
}
return $ret;
Since the length of "hiyall2008153639492" is 19 and the loop starts
at 0 and ends at 9 then the length of $ret will be 10.
John, I understand what you are saying here, but in my script, I'm not
looping $_[0] - $i times. I set my loop up to loop $_[0] - 9 times,
No. You set your loop up to loop length($_[0]) - 9 times. Since
"hiyall2008153639492" has a numeric value of 0 the loop would never end
if you did that.
Correction, the loop will never start.
John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/