Page 1 of 1

Invalid statement

Posted: Fri Apr 05, 2019 2:06 am
by Quinton B.
I'm trying to create a password strength tester.

Bellow is my current code:

Code: Select all

if mouseUp then
      repeat until t2s = false
         if mouseleave then
            put the num of chars of tT1 into t2t
            if tT1 <= 10 then
               answer "Please make your Password more than 10 characters long"
               set the text of tT1 to "Password"
               put true into t2s
            else
               put "0123456789" into tList156
               if any char from tList156 is not among tT1 then
                  answer "Please add a number to your Password"
                  put true into t2s
               else
                  put "`~!@#$%^&*()_-+=}{][|\<,>.?/" into tList175
                  if any char from tList175 is not among the text of tT1 then
                     answer "Please add a special character to your Password", "eg.`~!@#$%^&*()_-+=}{][|\<,>.?/"
                     put true into t2s
                  else
                     put false into t2s
                  end if
               end if
            end if
         end repeat
      end if
   end if
I can make it work if I make an extremely long version just as the other example show bellow:

Code: Select all

if "a" or "A" is among tT1 then
   put 1 into tC1
else
   put 0 into tC1
end if
if "b" or "B" is among tT1 then
   put 1 into tC2
else
   put 0 into tC2
end if
if tC1 + tC2 >= 1 then
   --password is strong
   put false into t2s
else
   --weak password
   put true into t2s
end if 
I really don't want to do the second option what is my best COA (Course of Action)?

Re: Invalid statement

Posted: Fri Apr 05, 2019 4:07 am
by dunbarx
Hi.

OK. Ready?

You simply must learn to use the switch control structure.

I think you wanted "if the mouse is up", not "if mouseUp" (same with "if mouseLeave")

MouseUp and mouseLeave are messages. They are not states of being. But you can test the condition of the mouse (if the mouse is up) and you can trap the mouseLeave message in its own handler.

Just for a start, the code snippet:

Code: Select all

 if mouseUp then
      repeat until t2s = false
         if mouseleave then
Would be something like:

Code: Select all

 if the mouse is up then
      repeat until t2s = false
         if the mouseLoc is not within the rect of the target then
You are testing the state of the mouse, and the loc of the cursor, to see if it is within the rect of the target object. Now this will not detect the event of actually leaving that target, only that is has indeed left. To detect the actual event, you must do so in another separate handler. We can help with that , but you will need to rethink your structure.

You cannot say "if any char from tList156 is..." you must say "if any char OF tList156 is..."

You cannot say " ...is not among the text of tT1...". You must say " ...is not in the text of tT1...", or better, " ...is not in tT1..."

These are all minor syntactical errors, and you will soon get better at the vocabulary. You already have a working sense of using LC to build gadgetry.

Write back often with all additional complaints.

Craig Newman

Re: Invalid statement

Posted: Fri Apr 05, 2019 8:16 am
by FourthWorld

Re: Invalid statement

Posted: Fri Apr 05, 2019 5:04 pm
by jacque
if any char from tList
Besides the minor syntax error, this doesn't do what you'd expect when speaking English. It doesn't check every character for compliance. "Any" is a shortcut for choosing a single random item from a list. If you need to check every character in the string you'll have to create a repeat loop that looks at each one.

In LC, we'd use "any" like this:

put any character of "abcdefg" - > f, for example

Re: Invalid statement

Posted: Fri Apr 05, 2019 6:36 pm
by dunbarx
What Jacque means (she intimated this was homework for you) is that you must deal with each character individually. So:

Code: Select all

  if any char from tList156 is not among tT1 then
has to be done like this:

Code: Select all

repeat for each char tChar in tList156
  if tChar is in tT1 then...
  end repeat
In your original thinking, you are asking LC to do just that, by assuming it will dissect all the chars of tList156 individually and see if they are in tT1. It will not; you must do it.

Craig

Re: Invalid statement

Posted: Fri Apr 05, 2019 7:36 pm
by jacque
What Jacque means (she intimated this was homework for you)
I did? Sorry, it wasn't intentional.

Re: Invalid statement

Posted: Fri Apr 05, 2019 8:15 pm
by dunbarx
Jacque.
I did? Sorry, it wasn't intentional.
Really? :shock:

Do you know who you are talking to? :mrgreen:

Don't you remember our homework repartee of a few years ago? :roll:

Ask Richard about apologizing. :wink:

Craig