Compare user string with and predefined file...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare user string with and predefined file...
# 1  
Old 11-25-2014
Compare user string with and predefined file...

i am trying to write shell script
how to write shell script which is ask for user id and password then compare both from two different file..
i have no idea how to compare with data present in file..

#!/bin/bash -e

read -p "User ID: " first
read -p "Password: " second

if [ X$first = X$second ];then
echo "Both Values are equal"
else
echo "Mismatch"
fi
# 2  
Old 11-25-2014
Hi niko420,

Try this:
if [ $first == "abc" ] && [ $secound == "efg" ]
then
echo "Match"
else
echo "MisMatch"
fi
# 3  
Old 11-25-2014
You will have to extract the information from the two files:
Code:
#! /bin/bash -e

read -p "User ID: " userid
stty -echo
read -p "Password: " password
stty echo

userkey=$(getuserkey "${userid}")
userpwd=$(getuserpwd "${userkey}")

if [[ -n "${userkey)" -o "${password}" != "${userpwd}" ]]; then
  echo Invalid username or password
  exit 1
fi

(shell psuedo-code, untested!)

Please keep in mind that both files would have to be readable by all users of this script, and the "password" would be stored as cleartext. You could set the script to run setuid, but that could raise other security issues. Perhaps sudo could be used to validate access, just have the script run:
Code:
sudo -u safeuser /path/to/therealscript

# 4  
Old 11-25-2014
grep can be handy to search for values in an external file, if you had a you file like user.dat like this:

Code:
guest:paSSword
reports:n0P


You could use it something like this

Code:
#!/bin/bash

read -p "User ID: " USER_ID
read -p "Password: " USER_PASS

if grep -qx "$USER_ID:$USER_PASS" user.dat
then
	echo "Both Values are equal"
else
	echo "Mismatch"
fi

Arguments for grep -q no output just set return code if found.. -x match entire line

Note: there are much better and safer ways to validate users against passwords and this is just an example of matching data against a file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert a user input string after matched string in file

i am having file like this #!/bin/bash read -p 'Username: ' uservar match='<color="red" />' text='this is only a test so please be patient <color="red" />' echo "$text" | sed "s/$match/&$uservar\g" so desireble output what i want is if user type MARIA this is only a test so please... (13 Replies)
Discussion started by: tomislav91
13 Replies

2. UNIX for Dummies Questions & Answers

Search for string in a file then compare it with excel files entry

All, i have a file text.log: cover6 cover3 cover2 cover4 other file is abc.log as : 0 0 1 0 Then I have a excel file result.xls that contains: Name Path Pass cover2 cover3 cover6 cover4 (1 Reply)
Discussion started by: Anamika08
1 Replies

3. Shell Programming and Scripting

Compare two string in two separate file and delete some line of file

Hi all i want to write program with shell script that able compare two file content and if one of lines of file have # at the first of string or nothing find same string in one of two file . remove the line in second file that have not the string in first file. for example: file... (2 Replies)
Discussion started by: saleh67
2 Replies

4. Shell Programming and Scripting

Help with File processing - Adding predefined text to particular record based on condition

I am generating a output: Name Count_1 Count_2 abc 12 12 def 15 14 ghi 16 16 jkl 18 18 mno 7 5 I am sending the output in html email, I want to add the code: <font color="red"> NAME COLUMN record </font> for the Name... (8 Replies)
Discussion started by: karumudi7
8 Replies

5. UNIX for Dummies Questions & Answers

Compare 2 files print the lines of file 2 that contain a string from file 1

Hello I am a new unix user, and I have a work related task to compare 2 files and print all of the lines in file 2 that contain a string from file 1 Note: the fields are in different columns in the files. I suspect the is a good use for awk? Thanks for your time & help File 1 123 232 W343... (6 Replies)
Discussion started by: KevinRidley
6 Replies

6. Shell Programming and Scripting

How to compare particular string, if it is equal put into a new file

Hi, I have a file (sample.txt) this file contains below text. ./au ./11.5.0 ./11.5.0/admin ./11.5.0/admin/driver ./po ./11.5.0 ./11.5.0/admin ./11.5.0/admin/driver ./xxsbx/11.5.0/java/src ./xxsbx/11.5.0/lib ./xxsel ./xxsel/11.5.0 ./xxsel/11.5.0/admin ./zfa ./zfa/11.5.0... (2 Replies)
Discussion started by: gagan4599
2 Replies

7. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

8. Shell Programming and Scripting

How to compare file name with a string

Hi, Suppose in some directory (/APPS/TEST) I have a file ABCTEST.csv. I want to write a IF condition in which I want to check if filename contains the string ABC then I will do certain operations . I have a variable having value as /APPS/TEST/ABCTEST.csv How Can I achieve this...please... (14 Replies)
Discussion started by: vishalaksha
14 Replies

9. Shell Programming and Scripting

Shell script to loop for a particular file in predefined path

Hi , i need a shell script to poll a particular file in a predefined directory , once that file is found , i need to launch another shell script . Eg i need to poll for A.txt in /home/username/Desktop once A.txt is created by Desktop(Created by another Script) , i need to launch another... (2 Replies)
Discussion started by: Vinod H C
2 Replies

10. Shell Programming and Scripting

Log File date compare for user defined range

:confused: Hi i am a noob and need a little help to finish my shell script. I am learning as i go but hit a problem. I am search thorugh logs(*.rv) files to find entires between two user defined dates, The script so far looks for the "START" and "END" of each entry at sees if it belongs To... (0 Replies)
Discussion started by: mojo24
0 Replies
Login or Register to Ask a Question