Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
3XC4L1B3R

it looks like my password reader reads enter as a key...

Question

I've been trying to make a simple password reader, but it just doesn't work...

Whenever I enter anything into the field,  another character will be added (in the form of an extra line break if pwchar is nil). At first, I thought the "dobreak" parameter would help, but all that does is print "incorrect" on the same line as the password...

local term = require("term")

local pw

term.write("enter password: ")
pw = (term.read(nil, false, nil, "*"))

if pw == "1234" then
  print("correct")
else
  print("incorrect")
end

image.png.26b491d211fe63183c9becb719a2c7ea.png

I've also tried other importing other peoples' password readers, to the same effect, so it has occurred to me that this may be a bug in OC. According to my modlist, the version I'm using is MC1.12.2-1.7.4.153. And I'm using the FTB direwolf20 1.12 modpack from twitch, if you need the rest of my modlist.

This has frustrated me for hours now... any help would be appreciated.

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

test things like `term.read()` in the lua shell, it'll help you see what is returned from it

io.read() does not return a newline (nor does io.stdin:readLine(true))

term.read() includes the newline in the return string (same as io.stdin:readLine(false)

local pw = (term.read({pwchar='*'}) or ""):gsub("\n$", "")

 

my use of {pwchar='*'} gets the same job done as your term.read(nil, false, nil, '*'), i just dont like the long param form of calling term.read

 

 

now, why is it this way? because it has been this way for years.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.