Hello!
I have i problem i was hoping you could help me with, I have to write a script that will ask the user for a username and password, and validate it through /etc/passwd and /etc/shadow.

I've looked all over the place for an answer to this and i just cant find it, ive tried generating a new password with the salt i get from the shadow file, and the command

openssl passwd -salt [I]salt[/I] [[I]password to verify[/I]]

but I just cannot get it to match the correct encryption of the password.

also, for that same proyect i have to enable creation of users without the useradd command, and remove them, i also have to enable password modification, without the passwd command, said user must have an encrypted password and supported by /etc/shadow... i was hoping some1 could help me out with where to start on that before i just plunge headfirst into editing the shadow file (shudders) :S

i only just booted into linux for the first time 2 weeks ago, so i could really use any help you can give me... :icon_cheesygrin:

yeah... i know, ive already done it with C, my teacher got mad at me... he said that was not what we where trying to do... but he just wont explain how to do it then, ive found out how to do the authentication now, ill post the code snipet in a few, but i still dont know how to create a user using shellscript and without the commands that are there specifically for that function, i mean, i could edit etc/passwd and /etc/shadow... but that prospect alone is scary... (dont want to blow my pc up), and i dont know that that's enough.

ok, here is what i used to validate the username and password, its not the full script but you can get the idea:

echo -n "Please insert username : "
	read usrname
	contrl=`cat /etc/passwd | grep $usrname`
	if [ "$contrl" != "" ]
	then
		usrchk=1
		echo
		echo -n "please insert password : "
		read -s password
		encrypt=`cat /etc/shadow | grep $usrname | cut -d: -f2 | cut -d$ -f 2`
		salt=`cat /etc/shadow | grep $usrname | cut -d: -f2 | cut -d$ -f 3`
		contrl=`openssl passwd -$encrypt -salt $salt $password`
		if [ "$contrl" = "`cat /etc/shadow | grep $usrname | cut -d: -f2`" ]
		then
			passchk=1
		else
			if [ "$contador" = 3 ]
			then
				echo "sorry, you have failed 3 times"
			else
				echo "Incorrect Password, you have failed $contador times, remember, you can only fail 3 times"
			fi
		fi
	else
		if [ "$contador" = 3 ]
		then
			echo "sorry, you have failed 3 times"
		else
			echo "Incorrect Password, you have failed $contador times, remember, you can only fail 3 times"
		fi
	fi

there is probably a simpler way to do this, but with the tools im allowed to use, this is what i came up with
"contador" is just a counter i made so you can only try 3 times

Edited 6 Years Ago by Korakos: Clarification mostly (and translating from spanish)

This article has been dead for over six months. Start a new discussion instead.