I know it's been 8 years; but for anyone still wondering, I've found a [simple 
code 
example](https://gist.github.com/mttaggart/aa67c96b61ebc1a9ba4cbfd655931492) 
that prints asterisks for password-input using `getch`:
    
    
    from terminal import getch
    from strutils import strip
    from strformat import fmt
    
    proc getPass(prompt = "Secret: "): string =
      stdout.write(prompt)
      while result == "" or result[^1] notin ['\x0D', '\n']:
        result.add getch()
        stdout.write("*")
      stdout.write("\n")
      return result.strip()
    
    # Example
    let password = getPass("What is your password? ")
    echo fmt"Your password = '{password}'"
    
    
    Run

Or you can just use [the one in the standard 
library](https://nim-lang.org/docs/terminal.html#readPasswordFromStdin%2Cstring)
 (no asterisks, just turns off printing):
    
    
    from terminal import readPasswordFromStdin
    from strformat import fmt
    
    let password = readPasswordFromStdin("What is your password? ")
    echo fmt"Your password = '{password}'"
    
    
    Run

Reply via email to