Answer needs to be in Linux. I am reading a username and password from text file userlist.txt. userlist.txt has about 20

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Answer needs to be in Linux. I am reading a username and password from text file userlist.txt. userlist.txt has about 20

Post by answerhappygod »

Answer needs to be in Linux. I am reading a username and
password from text file userlist.txt.
userlist.txt has about 20 usernames and passwords.
the format of all the text is username:password in a long
list . Can you tell me why this code is not reading in the
username and password??
also the code crashes after I enter in the zipcode
Thanks!
#Scripting Project 5, 5/8/2022, Proj5Script1
#You will build an ordering script.
#You will use multiple files for login verification, catalog
searches,
#demographic information, and storing order information.
#You will need to accomplish the following pieces in your
script.
#Prompt the user for a name and password.
#Verify the user's name and password against a user file.
#Allow the user to enter a Shipping Address.
#Use the Zipcode file to lookup their city.
#Allow the user to search the catalog for specific items.
#Allow the user to select items from the catalog and add to an
order
#Add items ordered to a file called orders.
#Include the following fields: Name, Address, City, State, Zip,
Items ordered,
#Item Cost(per item), Total Cost
#!bin/bash
#prompt user for name and password
echo "Enter your name: "
read name
echo "Enter your password: "
read password
#verify user's name and password against a user file
while read line
do
user=$(echo $line | cut -d ':'
-f1)
pass=$(echo $line | cut -d ':'
-f2)
if [ "$name" == "$user" ] && [
"$password" == "$pass" ]
then
echo
"Welcome $name"
break
else
echo
"Invalid username or password"
echo "Enter
your name: "
read
name
echo "Enter
your password: "
read
password
fi
done < userlist
#allow user to enter a shipping address
echo "Enter your address: "
read address
echo "Enter your zipcode: "
read zipcode
#use the Zipcode file to lookup their city
while read line
do
zip=$(echo $line | cut -d ':'
-f1)
city=$(echo $line | cut -d ':'
-f2)
state=$(echo $line | cut -d ':'
-f3)
if [ "$zipcode" == "$zip" ]
then
echo "Your city is
$city"
echo "Your
state is $state"
break
fi
done < zipcodes
#allow user to search the catalog for specific items
echo "Enter the item you want to search: "
read item
#allow user to select items from the catalog and add to an
order
while read line
do
item_name=$(echo $line | cut -d ':'
-f3)
item_cost=$(echo $line | cut -d ':'
-f4)
if [ "$item" == "$item_name" ]
then
echo "The
cost of $item is $item_cost"
echo "Do
you want to add this item to your order? (y/n)"
read
choice
if [
"$choice" == "y" ]
then

echo
"$name,$address,$city,$state,$zipcode,$item,$item_cost" >>
orders

break
else

echo "Enter the item you want to search:
"

read item
fi
fi
done < NSN_DATA
#allow user to print invoice of their order
echo "Do you want to print your invoice? (y/n)"
read choice
if [ "$choice" == "y" ]
then
echo "Name: $name"
echo "Address: $address"
echo "City: $city"
echo "State: $state"
echo "Zipcode: $zipcode"
echo "Item: $item"
echo "Item Cost: $item_cost"
echo "Total Cost: $item_cost"
fi
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply