[Gambas-user] How to input hide password into gambas command line project ?

Tobias Boege taboege at ...626...
Thu Oct 1 18:22:40 CEST 2015


On Thu, 01 Oct 2015, Yahoo wrote:
> Hello all,
> 
> Since few day I work on a little project that consist to a cli program written in Gambas3 where the first task is to ask to the user to enter a password but of course, all written character must be hidden.
> 
> I try to use INPUT instruction but all characters entered are automatically written on the terminal so it???s not a good solution.
> I try to use gb.ncurses to do the same work and a strange thing happens. Just enabling gb.ncurses on the project without any instruction to create a new Window (as described in the gb.ncurses tutorial) and automatically all characters written in console to the INPUT instruction are hidden.
>

If you use gb.ncurses, you must do all terminal I/O using gb.ncurses or else
you may mess up its internal state. That means instead of Input or Read you
have to use Window.Read().

The way gb.ncurses initialises the ncurses library (the normal way) creates
a clean new window, the standard screen, and you can't get rid of that.
Therefore gb.ncurses is useful only for projects which want a full-featured
TUI and would hence clean the screen anyway.

Indeed there are at least three better options if you just want to tempora-
rily disable echoing of input characters:

  (1) Use the "stty" program as shown in the attached project,
  (2) Use the termios.h functions from the C library via Extern (super
      ugly), or
  (3) Use gb.termios which is a component I have written for demonstration
      purposes and is not in the official source tree. Incidentally it
      brings the termios structures from point (2) to Gambas. You can find
      its sources here[0]. The test project available there does exactly
      hidden password input.

> This solution could work but I have other problem when for example I terminate the program, the terminal where the program is started become unusable. I don???t know why but in the end this solution is not usable in my case.
> 

What terminal becomes unusable? And what does "unusable" mean? If you
started the project from within the IDE and checked the "Use a terminal
emulator" option, it is normal that the terminal won't respond after the
process died (a possible interpretation of "unusable").

Once the Gambas process exits, there is no process left to use the terminal
(no shell is started by the IDE to host the Gambas process), but the window
is not destroyed. It just won't respond, so that you can read the last words
of your process. This behaviour is explicitly enforced by the IDE.

If this is not your case, then be more specific and send a project that
reproduces the problem.

Regards,
Tobi

[0] http://www-e.uni-magdeburg.de/tboege/gambas

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stty-input-password-0.0.1.tar.gz
Type: application/octet-stream
Size: 4728 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20151001/93acdb74/attachment.obj>


More information about the User mailing list