Write a script which enters username s& password & check that if the username = sugc& password=98765 then display the valid user message. Otherwise invalid user.

SOLUTION....

#!/bin/bash
# Script to check username & password with max 3 attempts

correct_user="sugc"
correct_pass="98765"
attempt=1
max_attempts=3

while [ $attempt -le $max_attempts ]
do
    echo "Attempt $attempt of $max_attempts"
    
    # Take username input
    read -p "Enter Username: " user
    
    # Take password input silently (hidden typing)
    read -s -p "Enter Password: " pass
    echo
    
    if [ "$user" = "$correct_user" ] && [ "$pass" = "$correct_pass" ]; then
        echo "✅ Valid User - Login Successful!"
        exit 0
    else
        echo "❌ Invalid Username or Password!"
    fi
    
    attempt=$((attempt+1))
done

echo "🚫 Maximum attempts reached. Access Denied."

OUTPUT

Leave a Reply

Your email address will not be published. Required fields are marked *

sign up!

We’ll send you the hottest deals straight to your inbox so you’re always in on the best-kept software secrets.