-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChallengeLoginSystem
52 lines (43 loc) · 1.42 KB
/
ChallengeLoginSystem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Predefined username and password
correct_user="admin"
correct_pw="12345"
# Account lockout settings
max_attempts=3 # Maximum allowed failed login attempts
lockout_duration=60 # Lockout duration in seconds (e.g., 60 seconds)
# Initialize failed attempts count
failed_attempts=0
# Account lockout state
account_locked=false
# Function to unlock the account
unlock_account() {
account_locked=false
failed_attempts=0
}
while true; do
# Check if the account is locked
if [ "$account_locked" = true ]; then
echo "Account is temporarily locked. Please wait."
sleep $lockout_duration
unlock_account
fi
# Prompt the user to enter a username
read -p "Enter your username: " entered_username
# Prompt the user to enter a password (hide input)
read -s -p "Enter your password: " entered_password
echo
# Check if entered credentials match predefined
if [ "$entered_username" == "$correct_user" ] && [ "$entered_password" == "$correct_pw" ]; then
echo "Login successful. Welcome, $entered_username!"
unlock_account
break
else
failed_attempts=$((failed_attempts + 1))
if [ $failed_attempts -ge $max_attempts ]; then
echo "Login failed. Account temporarily locked. Please wait."
account_locked=true
else
echo "Login failed. Please check your username and password."
fi
fi
done