diff --git a/src/lib_stdlib_unix/lwt_utils_unix.ml b/src/lib_stdlib_unix/lwt_utils_unix.ml index 7aa184272..4d4112699 100644 --- a/src/lib_stdlib_unix/lwt_utils_unix.ml +++ b/src/lib_stdlib_unix/lwt_utils_unix.ml @@ -136,6 +136,22 @@ let getaddrinfo ~passive ~node ~service = addr in Lwt.return points +let getpass () = + let open Unix in + (* Turn echoing off and fail if we can't. *) + let tio = tcgetattr stdin in + let old_echo = tio.c_echo in + let old_echonl = tio.c_echonl in + tio.c_echo <- false ; + tio.c_echonl <- true ; + tcsetattr stdin TCSAFLUSH tio ; + (* Read the passwd. *) + let passwd = read_line () in + (* Restore terminal. *) + tio.c_echo <- old_echo ; + tio.c_echonl <- old_echonl ; + tcsetattr stdin TCSAFLUSH tio ; + passwd module Json = struct diff --git a/src/lib_stdlib_unix/lwt_utils_unix.mli b/src/lib_stdlib_unix/lwt_utils_unix.mli index 9d43446c2..146a601d7 100644 --- a/src/lib_stdlib_unix/lwt_utils_unix.mli +++ b/src/lib_stdlib_unix/lwt_utils_unix.mli @@ -34,6 +34,10 @@ val getaddrinfo: node:string -> service:string -> (Ipaddr.V6.t * int) list Lwt.t +(** [getpass ()] reads a password from stdio while setting-up the + terminal to not display the password being typed. *) +val getpass : unit -> string + module Json : sig (** Loads a JSON file in memory *)