C program Implementation password secret input Linux system executable

Source: Internet
Author: User

Read and write user input, screen does not echo

Char *getpass (const char *prompt);

The getpass is used to read user input from the keyboard, but the screen does not echo.

The parameter prompt is the screen prompt character.

The function returns a string that is entered by the user's keyboard.

The screen does not indicate that the user entered the content, does not display any prompt message, that is, when switching users in Linux, the input password is not realistic.

The procedure is as follows:

1#include <stdio.h>2#include <unistd.h>3       4     intMainintargcChar*args[])5     {  6         //Call the Getpass function7         //parameter of function is prompt information8         //The return value of the function is what the user entered9         Char*password = Getpass ("Input your password:"); Ten         //output User-entered information Oneprintf"Password =%s\n", password);  A         return 0;  -     }   -  the  

To compile and execute the program :

    1. [Email protected] mycode]$ Gcc-o main MAIN.C
    2. [Email protected] mycode]$./main
    3. Input your password:------------here will not echo
    4. Password = 123456

C program Implementation password secret input Linux system executable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.