Loading ...
Sorry, an error occurred while loading the content.

inputsecret() showing cleartext...

Expand Messages
  • Konstantin Rozinov
    Hi folks, I have the following piece of code. It is activated via autocmd BufWriteCmd: if (v:version = 700) let s:passwd = inputsecret( Enter password: )
    Message 1 of 3 , Dec 1, 2005
    • 0 Attachment
      Hi folks,

      I have the following piece of code. It is activated via autocmd BufWriteCmd:

      if (v:version >= 700)
      let s:passwd = inputsecret("Enter password: ")
      let s:passwd_confirm = inputsecret("Confirm password: ")
      if ((s:passwd == s:passwd_confirm) && (s:passwd != ''))
      do stuff....
      do stuff....
      unlet s:passwd
      unlet s:passwd_confirm
      ......

      When the user issues :w, the password is replaced with *s as it is
      typed. However, when the user issues a :wq, the password is shown in
      cleartext! Is this a known bug or am I just misusing the function?

      Any ideas would be appreciated. Thanks!
      Konstantin Rozinov
    • Bram Moolenaar
      ... We could call that a bug. What happens is that Vim sets the terminal to cooked mode before writing the file, so that typehead for the shell isn t eaten by
      Message 2 of 3 , Dec 1, 2005
      • 0 Attachment
        Konstantin Rozinov wrote:

        > I have the following piece of code. It is activated via autocmd
        > BufWriteCmd:
        >
        > if (v:version >= 700)
        > let s:passwd = inputsecret("Enter password: ")
        > let s:passwd_confirm = inputsecret("Confirm password: ")
        > if ((s:passwd == s:passwd_confirm) && (s:passwd != ''))
        > do stuff....
        > do stuff....
        > unlet s:passwd
        > unlet s:passwd_confirm
        > ......
        >
        > When the user issues :w, the password is replaced with *s as it is
        > typed. However, when the user issues a :wq, the password is shown in
        > cleartext! Is this a known bug or am I just misusing the function?

        We could call that a bug. What happens is that Vim sets the terminal to
        cooked mode before writing the file, so that typehead for the shell
        isn't eaten by Vim. But this also means the tty gets a whole line of
        text before sending it to Vim and the characters are echoed.

        Try the patch below. This sets the terminal back to raw mode when
        obtaining a line from the user.


        *** ex_getln.c~ Thu Dec 1 18:17:24 2005
        --- ex_getln.c Thu Dec 1 19:24:38 2005
        ***************
        *** 301,306 ****
        --- 301,310 ----
        ui_cursor_shape(); /* may show different cursor shape */
        #endif

        + /* When inside an autocommand for writing "exiting" may be set and
        + * terminal mode set to cooked. Need to set raw mode here then. */
        + settmode(TMODE_RAW);
        +
        #ifdef FEAT_CMDHIST
        init_history();
        hiscnt = hislen; /* set hiscnt to impossible history value */

        --
        Microsoft: "Windows NT 4.0 now has the same user-interface as Windows 95"
        Windows 95: "Press CTRL-ALT-DEL to reboot"
        Windows NT 4.0: "Press CTRL-ALT-DEL to login"

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ download, build and distribute -- http://www.A-A-P.org ///
        \\\ help me help AIDS victims -- http://www.ICCF.nl ///
      • Konstantin Rozinov
        Hey Bram The patch worked. Thanks! Konstantin
        Message 3 of 3 , Dec 1, 2005
        • 0 Attachment
          Hey Bram

          The patch worked. Thanks!

          Konstantin

          At 10:32 AM 12/1/2005, Bram Moolenaar wrote:

          >Konstantin Rozinov wrote:
          >
          > > I have the following piece of code. It is activated via autocmd
          > > BufWriteCmd:
          > >
          > > if (v:version >= 700)
          > > let s:passwd = inputsecret("Enter password: ")
          > > let s:passwd_confirm = inputsecret("Confirm password: ")
          > > if ((s:passwd == s:passwd_confirm) && (s:passwd != ''))
          > > do stuff....
          > > do stuff....
          > > unlet s:passwd
          > > unlet s:passwd_confirm
          > > ......
          > >
          > > When the user issues :w, the password is replaced with *s as it is
          > > typed. However, when the user issues a :wq, the password is shown in
          > > cleartext! Is this a known bug or am I just misusing the function?
          >
          >We could call that a bug. What happens is that Vim sets the terminal to
          >cooked mode before writing the file, so that typehead for the shell
          >isn't eaten by Vim. But this also means the tty gets a whole line of
          >text before sending it to Vim and the characters are echoed.
          >
          >Try the patch below. This sets the terminal back to raw mode when
          >obtaining a line from the user.
          >
          >
          >*** ex_getln.c~ Thu Dec 1 18:17:24 2005
          >--- ex_getln.c Thu Dec 1 19:24:38 2005
          >***************
          >*** 301,306 ****
          >--- 301,310 ----
          > ui_cursor_shape(); /* may show different cursor shape */
          > #endif
          >
          >+ /* When inside an autocommand for writing "exiting" may be set and
          >+ * terminal mode set to cooked. Need to set raw mode here then. */
          >+ settmode(TMODE_RAW);
          >+
          > #ifdef FEAT_CMDHIST
          > init_history();
          > hiscnt = hislen; /* set hiscnt to impossible history value */
          >
          >--
          >Microsoft: "Windows NT 4.0 now has the same user-interface as Windows 95"
          > Windows 95: "Press CTRL-ALT-DEL to reboot"
          >Windows NT 4.0: "Press CTRL-ALT-DEL to login"
          >
          > /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
          >/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
          >\\\ download, build and distribute -- http://www.A-A-P.org ///
          > \\\ help me help AIDS victims -- http://www.ICCF.nl ///
        Your message has been successfully submitted and would be delivered to recipients shortly.