How do you use AS to do script "su" in a terminal window with a passwd

Hello to all you lovely scripterperople out there. I’ve been trying to make an applescript that will
prompt the user for a username and password and doing a do script “su “& user_name &””
before entering some_password at the prompt. I’d like to do this so i can write a script that can be
used by non-admin users to do a particular terminal comand. The reason i cant just do shell script
and sudo with administrator privilages is that one of the comands i want to use is /sbin/shutdown
-h +some_number and sleep comands, which cause AppleScript to stay open until the command is
complete. How do i get applescript to do a command in the terminal, enter the password and press
return?
This is what i have so far. It seems to work but for a reason unknown to me it causes the Terminal to quit.

set myUser to text returned of (display dialog "Please enter your login Username. Leave this field blank to log in as root user." default answer "")
if the text of myUser is "" then set myUser to "root"
end
set myPass to text returned of (display dialog "Please enter your login password for user \"" & myUser & "\"." default answer "" with hidden answer)
if the text of myUser is "root" then set myUser to ""
end
tell application "Terminal"
	launch
	delay 1
	do script "echo " & myPass & " | su " & myUser & "" in window 1
	quit
	do script "whateveryouwanttodo" in window 1
end tell

Any help in this would be awesom!
Thanx, Roho

this might work for ya

set myUser to text returned of (display dialog "Please enter your login Username. Leave this field blank to log in as root user." default answer "")
if the text of myUser is "" then set myUser to "root"
end
set myPass to text returned of (display dialog "Please enter your login password for user \"" & myUser & "\"." default answer "" with hidden answer)

tell application "Terminal"
	launch
	delay 1
	do script "su " & myUser & "" in window 1
	set mykeys to (myPass & return) as Unicode text
	tell application "System Events"
		keystroke mykeys
	end tell
end tell

Thanks heaps chris, that worked great. I had to put in a delay
between the tell app “System Events” and “keystroke mykeys”
because the script typed in the password and pressed return
before the password request had arrived, but now everything is
going really well! Cheers, Rohan

And even 10 years later your post still helped resolve my issue, thanks!