Created
October 28, 2019 23:33
-
-
Save ampersanda/4647d16a5d335dce8dcd49ff47fd851e to your computer and use it in GitHub Desktop.
CLI - read password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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