Home > Mobile >  Bash: How to find a specific char in a string
Bash: How to find a specific char in a string

Time:11-09

I have the assignment to write a bash script to validate password strength and one of the requirements is: Include both the small and capital case letters.

if  [[ $PASSWORD == ${PASSWORD,,} ]] &&
    [[ $PASSWORD == ${PASSWORD^^} ]]; then
        valid=true
else
        valid=false
fi

It always will give me false.

Can anyone please help me, thank you!

CodePudding user response:

Your test is always false except if "PASSWORD" do not contains letters!

#! /bin/bash

...

if  [[ "$PASSWORD" =~ [a-z] ]] && [[ "$PASSWORD" =~ [A-Z] ]]; then
        valid=true
else
        valid=false
fi

CodePudding user response:

The Password variable is the input, of course, one of the requirements to validate the password is that the password has to contain upper case letters, lower case letters, and numbers. It would be enough even if only one letter is upper case and one is the lower case but for that don't I need to go over the string with for loop and compare each letter to upper case and lower case? Only one case of both of them would be eanogh.

  • Related