Skip to content

Instantly share code, notes, and snippets.

@ampersanda
Created October 28, 2019 23:33
Show Gist options
  • Save ampersanda/4647d16a5d335dce8dcd49ff47fd851e to your computer and use it in GitHub Desktop.
Save ampersanda/4647d16a5d335dce8dcd49ff47fd851e to your computer and use it in GitHub Desktop.
CLI - read password
;; password input is visible when use run
;; but it's invincible if it's executed using java -jar target/your-uberjar-standalone.jar
(defn read-password [prompt]
;; Based on https://groups.google.com/forum/#!topic/clojure/ymDZj7T35x4
(if (= "user" (str (.getName *ns*)))
(do
(print (format "%s [will be echoed to the screen]" prompt))
(flush)
(read-line))
(let [console (System/console)
chars (.readPassword console "%s" (into-array [prompt]))]
(apply str chars))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment