AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Searching for specific special characters in Matchlist

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
scouchman



Joined: 28 Apr 2004
Posts: 45

PostPosted: Thu Apr 27, 2006 2:53 pm    Post subject: Searching for specific special characters in Matchlist Reply with quote

I'm writing a password Reset program using the excellent Using VBscript in ahk without a temporary file info and some Active Directory VB scripts.

To save time on errors (since the VB script still takes time to call to the server), I'm programming the password parameters in AHK before it goes to the VB script and fails on the server. So, for one of the parameters I need to have it detect "special characters", and running into a problem with two characters: the comma and the accent (,`).

In the following code test:
I've tried them "straight": ,,,`,
I've tried them with the literal: ,`,,``,
And tried them in their own variables (shown here)

Is there any way for it to recognize these?
(for checking the accent, I use Pass = password`1)

Code:
Pass = password,1
Comma = ,
Accent = `

If Pass contains ~,!,@,#,$,`%,^,&,*,(,),-,_,=,+, ,;,:,',",<,.,>,/,?, ,|,`\,%comma%,%accent%
 {
  Msgbox, Found the special Character`nPassword: %Pass%
 }
Else
  MsgBox, No special character found in Password: %Pass%
Return

_________________
Scott F Couchman
Back to top
View user's profile Send private message AIM Address MSN Messenger
wOxxOm



Joined: 09 Feb 2006
Posts: 319

PostPosted: Thu Apr 27, 2006 3:15 pm    Post subject: Reply with quote

I would use char-by-char checking in a loop using instr check
Back to top
View user's profile Send private message Send e-mail Visit poster's website
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Thu Apr 27, 2006 3:36 pm    Post subject: Reply with quote

The "accent" (backtick) problem is trivial:
Pass = password``1 ; Must be doubled to put it in the string
; or use the following for test:
InputBox Pass
If Pass contains ?,``,!

It works well.

Now, I couldn't test the comma, despite what is described in the help "Two consecutive commas results in a single literal comma."
Obviously, it is was designed for a comma along some other characters, no for a single comma.
Pass = password,1
If Pass contains ?,d,,1,!

works well too.
But If Pass contains ?,,,,! doesn't work, neither ?,,,! nor ?,,! nor ?,`,,! (why not?) nor ?,!,, nor ?,!,,, nor ?,%comma%,! nor ?,!,%comma% nor %comma%,?,!
PS.: No need for `\, backslash has no signification in AHK (beside being a path separator).
Aha! Found it:
comma = ,,
If Pass contains %comma%,~,!,@,#,$,`%,^,&,*,(,),-,_,=,+, ,;,:,',",<,.,>,/,?, ,|,\,``

%comma% must be at the start of the MatchList! It won't work in the middle or at the end...
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
wOxxOm



Joined: 09 Feb 2006
Posts: 319

PostPosted: Thu Apr 27, 2006 3:57 pm    Post subject: Reply with quote

I would use this code in any programming language, it's very universal with no restrictions put to literal chars. Very visual without those awful numerous commas which cause me go coma Wink The only trick is to repeat doublequote twice (because it's an expression passed to inStr)

Code:
inputbox,pass,Password,Enter password:,HIDE
stringlen,passlen,pass
passOK=1
loop,%passlen%
{
   stringmid,passchar,pass,%A_Index%,1
   if (inStr("!@#$%^&*()_+=-,.<>/?/:""'|\[]{}`~",passchar))
   {
      passOK=0
      break
   }
}
if (passOK)
   msgbox Password is OK
else
   msgbox Password contains special chars
Back to top
View user's profile Send private message Send e-mail Visit poster's website
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Thu Apr 27, 2006 4:25 pm    Post subject: Reply with quote

1) An explicit loop is slow, even more with repeated InStr
2) I would use Loop Parse instead of a numerical loop with a StringMid (slow too)
3) You still need to double the backtick in the string
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
scouchman



Joined: 28 Apr 2004
Posts: 45

PostPosted: Thu Apr 27, 2006 4:57 pm    Post subject: Reply with quote

Thanks all. Here's the code I ended up with. I swear when I started messing with it I needed the `\, not just \ and `` wasn't working. Wondering if making the comma the FIRST entry (and why the double comma for that?) "fixed" everything else. Not sure, is this a bug then?

Code:
inputbox,pass,Password,Enter password:, ; to test any password

If Pass contains ,,,~,!,@,#,$,`%,^,&,*,(,),-,_,=,+, ,;,:,',",<,.,>,/,?, ,|,\,[,],{,},``
    Msgbox, Found the special Character`nPassword: %Pass%

Else
   MsgBox, No special character found in Password: %Pass%
Return


Tried all the special characters and worked this time.
_________________
Scott F Couchman
Back to top
View user's profile Send private message AIM Address MSN Messenger
wOxxOm



Joined: 09 Feb 2006
Posts: 319

PostPosted: Thu Apr 27, 2006 9:10 pm    Post subject: Reply with quote

PhiLho wrote:
1) An explicit loop is slow, even more with repeated InStr
2) I would use Loop Parse instead of a numerical loop with a StringMid (slow too)
3) You still need to double the backtick in the string


seems now quite offtopic Wink but loop,parse is of course better. But I never saw passwords longer than 30 chars, so it's not the case I think. And why do u think inStr is slow? isn't it lowlevel asm-coded function which is accomplished extremely fast? I wrote in asm and I remember that I didn't compare strings all-length, instead I used repetitive "rep scasb". By the way I checked sources of AutoHotKey - inStr is very effective, it uses several pointer assignments on init, then just calls strstr2 function, exactly as I thought.
By the way I rewrote rajat's 320mph to use inStr instead of consequential loop,parse and this script became up to 3000 times faster (in case there is only one match found - 0.1 ms vs 3 secs processing list of 15000 filepaths assembled in one string of 1 meg). So there are cases when loop,parse is beaten to death (and beyond) by inStr Wink
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group