Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password Protect Menus..

Status
Not open for further replies.

AdamCoombs

Technical User
May 22, 2002
51
0
0
GB
Hi there,

I am writing a case statement for a menu script but i need certain parts of the menu password protected.
Any idea how to do it?

cheers
Adam
 
You could prompt the user for a password and use the password to attempt to decrypt a file containing a word.
You can the compare the output of the crypt command against the file to see if it matches a prdefined word.

e.g.

create a file called pass.crypt containing the word valid and using the password guessme (as below)

echo "valid" > pass
crypt guessme < pass > pass.crypt
rm pass

Now in your script have a function to validate a passwd that you have prompted them for
something like ...

fn_validatePass()
{
$1=Passwd
if [ `crypt $Passwd < pass.crypt` = &quot;valid&quot; ]
then
echo &quot;Passwd OK&quot;
else
echo &quot;Bad passwd&quot;
fi
}

Obviously you'll have to tailure it to meet your requirements but it's better than hard coding a variable into a script and comparing it with user input.

Matt.
 
Depending upon your requirements and number of users, you may be able to do something similar to what I did...
if [ $LOGNAME = &quot;bob&quot; ] || [$LOGNAME = &quot;dave&quot; ]
then
<command>
else
echo &quot;Not authorized&quot;
fi


*This is rather simplistic, but all I really needed to do was keep some users from accessing certain options that they had no business executing. In the end, to avoid questions from users asking why they weren't authorized, I made a top level menu that had all of the options available for admin users and the else displays a 2nd menu where the restricted options weren't even listed. That has worked well because they don't miss what they can't even see (or know exists) ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top