kein echo bei eingabe



  • Hallo,

    ich suche eine funktion oder was auch immer die ein wort(passwort) in einen buffer(den ich vorgebe also nicht die passwd struct) schreibt, ohne dass das wort am bildschirm erscheind(also ohne echo!)

    kennt jemand so eine funktion?

    danke
    videoseven

    P.S. Gibts hier keine Suchfunktion ???



  • man: termios(3)
    man: getpass(3) wenn es sein muss ...



  • Hier ist die konkrete Lösung:

    /*
        password.c - Passwortabfrage ohne Echo
    */
    
    # include <stdio.h>
    # include <unistd.h>
    # include <fcntl.h>
    # include <termios.h>
    
    int main()
     {
      int old_flags;
      char password[16];
      struct termios term_attr;
    
      if (tcgetattr(STDIN_FILENO, &term_attr) != 0)
       {
        perror("password: tcgetattr() failed");
        return(1);
       }             /* alte Einst. sichern */
      old_flags = term_attr.c_lflag;
      term_attr.c_lflag &= ~ECHO;
      if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &term_attr) != 0)
        perror("password: tcsetattr() failed");
    
      printf("password: ");
      scanf("%15s", password);
                /* Std.-Eingabe wie vorher */
      term_attr.c_lflag = old_flags;
      if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &term_attr) != 0)
        perror("password: tcsetattr() failed");
    
      if (strcmp(password, "secret") == 0)
        printf("\npassword accepted.\n");
      else
        printf("\nwrong password.\n");
    
      return(0);
     }
    

    Das Beispiel stammt aus meinem Buch "C und Linux" http://home.t-online.de/home/AuM.Graefe/c_und_linux.html


Anmelden zum Antworten