Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Shell program with username and password Post 302398712 by thedemonhunter on Thursday 25th of February 2010 02:02:27 PM
Old 02-25-2010
vivekraj, you seem to understand what i need to do. I attempted something similar but i was having trouble comparing the two (username and password). What if i wanted to do this for multiple users? Would i use a CASE statement? such as:

Code:
case $username in
    alex ) pass=alex2;;
    sean ) pass=sean2;;
    ashley ) pass=ashley2;;
    # *) echo "error"
esac

But then i'm thinking this would affect the whole code and you would need the names as such: alex | sean | ashley.

What do you guys think?

---------- Post updated at 11:35 AM ---------- Previous update was at 10:51 AM ----------

also guys, this is what i had so far. i know it's wrong (especially the * part, it doesn't work) but like i said i am very new to this. i was trying to do this for one user first but i actually want to do multiple like i mentioned.

Code:
#!/bin/sh

echo "Enter login name and password"
read trythis

if [ $trythis = "Aarin_dtfc" ]
then
	echo "You are logged in!"
else [ $trythis = "Aarin_*" ]
	echo "Wrong password!"
	exit 1
else [ $trythis = "*_dtfc" ]
	echo "Login name is not recognized!"
	exit 2
fi
exit 0



---------- Post updated at 02:02 PM ---------- Previous update was at 11:35 AM ----------

ok i rewrote the code to this:

Code:
#!/bin/sh
echo "Enter username"
read username
if [ $username = "Aarin" ]
then  
 echo Enter password
 read password
case $username in
 Aarin ) pass=dtfc;;
 Rick ) pass=unpo
esac
while [ "$password" != "$pass" ]; do
 echo "Wrong password!"
 return 1
done
echo "You are logged in!" 
return 0
else
 echo "Login name not recognized"
fi
return 2

the only thing i am having trouble doing is adding multiple usernames to the if statement

Last edited by pludi; 02-25-2010 at 04:17 PM.. Reason: Please use code tags.......
 

10 More Discussions You Might Find Interesting

1. Programming

getting username from a c program in unix

How to get the user name of the Operating system from a c program. eg:- -rw-r----- 1 gkuser srth1 292 Jul 27 19:28 u1.txt i need to get gkuser as the result? (3 Replies)
Discussion started by: Rajeshsu
3 Replies

2. Shell Programming and Scripting

username password in script

Can we write a script to telnet to a unix server from unix with the username and password hardcoded in the script?? something like ssh a@b -p password ??? (5 Replies)
Discussion started by: roshanjain2
5 Replies

3. Shell Programming and Scripting

Read Oracle Username password SID from single file and pass it to shell

Dear All I am trying to write one shell which will be running through Cron which contain one SQL query. But I want to draw/fetch the Username password and Instance name (required to loging to the database) from one single file to run that SQL query . Also this file contain details of multiple... (2 Replies)
Discussion started by: jhon
2 Replies

4. UNIX for Dummies Questions & Answers

How can i hide username/password

hi all, i run sqlplus command on unix(HP-UX) like "sqlplus username/password@serverA @deneme.sql" but when someone run "ps -ef | grep sqlplus", it can see my username and password :( How can i hide username and password. thanx. (1 Reply)
Discussion started by: temhem
1 Replies

5. UNIX for Advanced & Expert Users

Login through SFTP using username and password

Hi All, I want to login to a server through SFTP by giving username and password, in an automated script. I know that this can be done through public key authentication, but my requirement is to login ONLY through username and password. I am using GNU/Linux server. Please advise me !!!... (4 Replies)
Discussion started by: sparks
4 Replies

6. Shell Programming and Scripting

Asking username and password in the middle of the Shell/perl script

Can any body help me to find out the logic I have a script chkcomponent.pl Which give some output Like component1 userid: u1 component2 userid: u2 component3 userid: u1 . . #The no of components are different in different times run Now I want this chkcomponent.pl script... (1 Reply)
Discussion started by: pareshpatra
1 Replies

7. Shell Programming and Scripting

Username and password

Hi I am new to using unix and am struggling with a script i am writing. What i am trying to do is get a user to enter a username, check the original file i created with username and pin to see if their is a corresponding entry. Next ask the user to enter the pin and see if this matches... (5 Replies)
Discussion started by: somersetdan
5 Replies

8. UNIX for Dummies Questions & Answers

How do you reset username/password

Picked up a 3b2 running System V. Works fine, but it requires a username and password. Is the username "root" or "sysadm"? How do I find out and how to I reset it or bypass it? Thanks. (2 Replies)
Discussion started by: TanRuNomad
2 Replies

9. Programming

Getting username from an informix 4gl program in UNIX

How to get the user name of the Operating system from an Informix 4gl program. eg:- -rw-r----- 1 gkuser srth1 292 Jul 27 19:28 u1.txt i need to get gkuser as the result? (0 Replies)
Discussion started by: enriquegm82
0 Replies

10. Shell Programming and Scripting

Passing Username & password through shell script to java code

Hi, I have a shell script (script.sh) in which we are calling java code which asks for Username: Password: for authentication purpose currently we are passing the credential manually and run the script. but I am trying echo -e "user_id\npassword" | script.sh but its not... (1 Reply)
Discussion started by: rakeshtomar82
1 Replies
LDAP_COMPARE(3) 							 1							   LDAP_COMPARE(3)

ldap_compare - Compare value of attribute found in entry specified with DN

SYNOPSIS
mixed ldap_compare (resource $link_identifier, string $dn, string $attribute, string $value) DESCRIPTION
Compare $value of $attribute with value of same attribute in an LDAP directory entry. PARAMETERS
o $link_identifier - An LDAP link identifier, returned by ldap_connect(3). o $dn - The distinguished name of an LDAP entity. o $attribute - The attribute name. o $value - The compared value. RETURN VALUES
Returns TRUE if $value matches otherwise returns FALSE. Returns -1 on error. EXAMPLES
The following example demonstrates how to check whether or not given password matches the one defined in DN specified entry. Example #1 Complete example of password check <?php $ds=ldap_connect("localhost"); // assuming the LDAP server is on this host if ($ds) { // bind if (ldap_bind($ds)) { // prepare data $dn = "cn=Matti Meikku, ou=My Unit, o=My Company, c=FI"; $value = "secretpassword"; $attr = "password"; // compare value $r=ldap_compare($ds, $dn, $attr, $value); if ($r === -1) { echo "Error: " . ldap_error($ds); } elseif ($r === true) { echo "Password correct."; } elseif ($r === false) { echo "Wrong guess! Password incorrect."; } } else { echo "Unable to bind to LDAP server."; } ldap_close($ds); } else { echo "Unable to connect to LDAP server."; } ?> NOTES
Warning ldap_compare(3) can NOT be used to compare BINARY values! PHP Documentation Group LDAP_COMPARE(3)
All times are GMT -4. The time now is 02:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy