FoxPro Programming
wwRegEx example
Gravatar is a globally recognized avatar based on your email address. wwRegEx example
  Kathy
  All
  Oct 30, 2022 @ 08:58am

Hello Rick and friends,
I need a password strength checker in Fox, would you think if I can use wwRegEx class?
And if yes, could you please let me know if there's an online example on how to use it?
Thank you in advance,
Kathy

Gravatar is a globally recognized avatar based on your email address. re: wwRegEx example
  Rick Strahl
  Kathy
  Oct 31, 2022 @ 12:32am

I would just manually write code for that.

Check for:

  • Length (whatever you choose - I'd say 10 char minimum)
  • Upper and Lower
  • Number
  • One Special Character

Whatever you do let people clearly know what's expected of your passwords otherwise it's a pain in the ass to guess...

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwRegEx example
  Kathy
  Rick Strahl
  Oct 31, 2022 @ 07:09am

Thanks a lot Rick.
And if I want to use something like the following code in C# (found online) that gives scores to show the level of the strength, would you please advise on how to get the returned value by the function?

        public enum PasswordScore
        {
            Blank = 0,
            VeryWeak = 1,
            Weak = 2,
            Medium = 3,
            Strong = 4,
            VeryStrong = 5
        }
        public PasswordScore CheckStrength(string password)
        {
            int score = 0;

            if (password.Length < 1)
                return PasswordScore.Blank;
            if (password.Length < 4)
                return PasswordScore.VeryWeak;

            if (password.Length >= 8)
                score++;
            if (password.Length >= 12)
                score++;
            if (Regex.Match(password, @"/\d+/", RegexOptions.ECMAScript).Success)
                score++;
            if (Regex.Match(password, @"/[a-z]/", RegexOptions.ECMAScript).Success &&
                Regex.Match(password, @"/[A-Z]/", RegexOptions.ECMAScript).Success)
                score++;
            if (Regex.Match(password, @"/.[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]/", RegexOptions.ECMAScript).Success)
                score++;

            return (PasswordScore)score;
        }

I'm not sure why I cannot see the function by:

loFox = loBridge.createinstance(...)
? loFox. && loFox doesn't show funciton CheckStrength!

And I'm not sure if/how I should use GetEnumValue, etc. for this case:

loBridge.GetEnumValue(...)

I would appreciate your advice on this.
Thanks,
Kathy

Gravatar is a globally recognized avatar based on your email address. re: wwRegEx example
  Rick Strahl
  Kathy
  Oct 31, 2022 @ 12:02pm

Is this your code (ie. you're compiling it)?

If so - change the signature to public static int to remove the enum from the equation - you can cast the result to return (int) score.

loBridge = GetwwDotnetBridge()
lnScore = loBridge.InvokeStaticMethod("YourNamespace.PasswordCheckerClass",CheckPassword,"seekrit#2")
public static int CheckPassword(string password)
{
   var score = PasswordScore.Blank;

   ...

   return (int) score;
}

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwRegEx example
  Kathy
  Rick Strahl
  Oct 31, 2022 @ 01:36pm

It was the lack of knowledge about enum 😄
Sure will do, thank you so much Rick.
Kathy

© 1996-2024