Re: Creating a Logon Form

[email protected] ("John W. Krahn") Thu, 11 Dec 2008 09:21:06 -0800
Newsgroups perl.beginners.cgi
Message-ID <[email protected]>
PekinSOFT wrote:
> 
> John W. Krahn wrote:
>> [email protected] 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.


> so what you are describing shouldn't be happening.  The logic that I
> was attempting with this loop was to add each character, one at a
> time, from the provided string to the $ret variable, stopping 9
> characters shy of the end of the string.

However substr(length($_[0]) - $i, 1) does not use the provided string, 
it uses the string created by length($_[0]) - $i, which is the numeric 
length of the provided string minus the value of $i converted to a string.


> However, with it set up the
> way it is, for some reason I'm either getting the 9 characters that I
> didn't want or a whole other bunch of 9 characters that I have no clue
> from whence they came.

I just explained, again, where they came from.



John
-- 
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov