I have an ssh server that has a user named newuser. When bash starts, I run this Lua script.


Code:

log = io.open("/etc/.users_created", "W")

os.execute("clear")
print("Welcome to Closet Server!")
print("------------------------------")
io.write("What's your full name? (Type n! is you don't want to): ")
fullName = io.read()
io.write("What will your login be?: ")
login = io.read()
io.write("What will your password be?: ")
passwd = io.read("*")
io.write("One more thing. Who is Brett's favorite pokemon?: ")
verify = io.read()
if string.lower(verify) == "*" then
 print()
 print("Okay! Please wait, we are creating your account")
 os.execute([[sudo useradd ]] ..login.. [[ -p ]] ..password.. [[ -m]])
 log.write([[Full Name: ]] ..fullName.. [[/nUser: ]] ..login.. [[/nPasswd: ]] ..passwd.. [[/n/n]])
 print("You are now a user on Closet Server! Press enter to logout.")
 io.read()
else
 print()
 print("You did not verify correctly.")
 print("GTFO.")
 print("Press enter to logout.")
 io.read()
end
os.execute("exit")


Don't worry about the verify == "*". I just blocked out the verification keyword. Anyways, the error I get is:

Code:

lua: newuser_script:11: bad argument #1 to `read' (invalid format)
stack traceback:
        [C]: in function `read'
        newuser_script:11: in main chunk
        [C]: ?


What's up with that?
That's because io.read("*") is not valid. Some valid options are "*all", "*line", "*number", or a number constant to denote how many characters would be read.

http://www.lua.org/pil/21.1.html
Hmm. I was trying to display the characters as asterisks not plaintext. I should stop playing Tekkit Razz

Anyways, how would I get the correct characters but not display them?
A quick Google search says that basically, you can't. Here's the StackOverflow thread that seems relevant to your question:

http://stackoverflow.com/questions/8748228/password-input-function-in-lua
I don't know how to do this in Lua, but you could make it so that it reads the password like sudo or su, i.e. without showing the characters or anything to represent the characters.
souvik1997 wrote:
I don't know how to do this in Lua, but you could make it so that it reads the password like sudo or su, i.e. without showing the characters or anything to represent the characters.
Indeed, I thought of that as well, but based on the StackOverflow question (which includes a clause about that possibility) I figured it was impossible in Lua.
You might want to consider using a Lua binding of the Curses or NCurses library, which is small and supports raw key input. Or, if this isn't meant to be portable between system, abuse of the os.execute() command provided with a shell command that would take input like such would also work.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement