 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
scouchman
Joined: 28 Apr 2004 Posts: 45
|
Posted: Thu Apr 27, 2006 2:53 pm Post subject: Searching for specific special characters in Matchlist |
|
|
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 |
|
 |
wOxxOm
Joined: 09 Feb 2006 Posts: 319
|
Posted: Thu Apr 27, 2006 3:15 pm Post subject: |
|
|
| I would use char-by-char checking in a loop using instr check |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Thu Apr 27, 2006 3:36 pm Post subject: |
|
|
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 |
|
 |
wOxxOm
Joined: 09 Feb 2006 Posts: 319
|
Posted: Thu Apr 27, 2006 3:57 pm Post subject: |
|
|
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 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 |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Thu Apr 27, 2006 4:25 pm Post subject: |
|
|
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 |
|
 |
scouchman
Joined: 28 Apr 2004 Posts: 45
|
Posted: Thu Apr 27, 2006 4:57 pm Post subject: |
|
|
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 |
|
 |
wOxxOm
Joined: 09 Feb 2006 Posts: 319
|
Posted: Thu Apr 27, 2006 9:10 pm Post subject: |
|
|
| 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 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  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|