# #TWSBashBlazeChallenge - Day 3

## Challenge: User Account Management

In this challenge, we will create a bash script that provides options for managing user accounts on the system. The script should allow users to perform various user account-related tasks based on command-line arguments.

### Part 1: Account Creation

1. Implement an option `-c` or `--create` that allows the script to create a new user account. The script should prompt the user to enter the new username and password.
    
2. Ensure that the script checks whether the username is available before creating the account. If the username already exists, display an appropriate message and exit gracefully.
    
3. After creating the account, display a success message with the newly created username.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690984994527/ff2cd795-2256-4891-9a8f-89aa470d00ae.png align="center")

I have implemented both when the user enters "-c" or "--create". You can see in /etc/passwd file, both users have been created.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690985270391/c7fbc659-c429-4580-8323-f1d08be393dc.png align="center")

It will give an error if the username already exists.

### Part 2: Account Deletion

1. Implement an option `-d` or `--delete` that allows the script to delete an existing user account. The script should prompt the user to enter the username of the account to be deleted.
    
2. Ensure that the script checks whether the username exists before attempting to delete the account. If the username does not exist, display an appropriate message and exit gracefully.
    
3. After successfully deleting the account, display a confirmation message with the deleted username.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690985100233/2e493119-7a73-465d-a8ae-dbdcc0a5c700.png align="center")

I have implemented both when the user enters "-d" or "--delete". You can see in /etc/passwd file, both users have been deleted.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690985304322/d514200b-3fd1-4b53-86ab-e62ec961e333.png align="center")

It will give an error if the user to be deleted doesn't exist.

### Part 3: Password Reset

1. Implement an option `-r` or `--reset` that allows the script to reset the password of an existing user account. The script should prompt the user to enter the username and the new password.
    
2. Ensure that the script checks whether the username exists before attempting to reset the password. If the username does not exist, display an appropriate message and exit gracefully.
    
3. After resetting the password, display a success message with the username and the updated password.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690985186925/c826cde0-b11d-4830-9479-6f9cf3924859.png align="center")

I have implemented both when the user enters "-r" or "--reset". You can see the password can be reset both ways.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690985368467/4200c19c-60f5-4bfa-89bd-6201c9a9e6be.png align="center")

It will give an error if the password of the user to be reset doesn't exist.

### Part 4: List User Accounts

1. Implement an option `-l` or `--list` that allows the script to list all user accounts on the system. The script should display the usernames and their corresponding user IDs (UID).
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690985464326/021c3494-6f22-4fcd-8808-efa9501f3ee8.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690985482662/bc21f828-e968-46fb-b9bf-d68e02591e28.png align="center")

I have implemented both when the user enters "-l" or "--list". You can see the list is getting printed both ways.

### Part 5: Help and Usage Information

1. Implement an option `-h` or `--help` that displays usage information and the available command-line options for the script.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690985732025/b478e39a-634e-4db1-9a4b-203100290d10.png align="center")

I have implemented three ways to display the options- when the user enters "-h" or "--help" or no argument. You can see the help list is getting printed.

### When a user enters an invalid option

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690986021867/19ec2f2f-3182-4097-bfa7-ab11fa23d09b.png align="center")

This will tell the user that the argument passed is invalid and tells them to choose from the given options.

You can find the solution here - [https://github.com/shivaniii23/BashBlaze-7-Days-of-Bash-Scripting-Challenge/tree/main/Challenges/Day\_3](https://github.com/shivaniii23/BashBlaze-7-Days-of-Bash-Scripting-Challenge/tree/main/Challenges/Day_3)

This Day 3 challenge was good. Learnt a lot. Let's see tomorrow what's there for Day 4.
