tags:

views:

55

answers:

1

I'm trying to write a sh coding to get the user to authenticate the password by comparing the user input to the first 32 characters of a file. So basically if the password is correct it would run TaskMenu.csh if its wrong the program would exit.

#!/bin/sh
clear
echo -e " Please Enter the Password to access the TaskMenu:"
read PW
if (! -e "$PASSWORD.txt")
then
        echo -n "The file doesn't exist"
        echo kil
        exit
else
        ...(i have no clue what to do)...

Please help

+1  A: 
if [ "$PW" = $(cat "$PASSWORD.txt | head -c 32) ]
then
    ./TaskMenu.csh
else
    echo Authentication failed.
    exit 3
fi

Run with bash -x, or add set -x to the top of your source to see what strings are being passed around.

Matt Joiner
Doesn't the fact that you can run this with bash -x (More likely, tcsh -x, but basically the same thing) and get the name of the file containing the password completely invalidate this method for password authentication?
reemrevnivek
ohhh ok thanks that is the part that i need thanks! ;)
GuzzyD
@reemrevnivek: That's a separate issue.
Matt Joiner
@Matt - I understand that it's not the problem, but wanted to point it out in case a beginner didn't realize this, and tried something like chmod 111'ing the script. I think I should have made it a statement instead of a question.
reemrevnivek