Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 297899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:40:54+00:00 2026-05-12T06:40:54+00:00

I could use getpass() to get a password. However, the man page says: This

  • 0

I could use getpass() to get a password. However, the man page says:

This function is obsolete. Do not use
it.

What is the current way to get a password from the user’s terminal without echoing it, in a POSIX-compliant way? [Originally I said “portably”, but my intention was to avoid using an obsolete function.]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:40:55+00:00Added an answer on May 12, 2026 at 6:40 am

    this should work on linux/macosx, a windows version should use Get/Set ConsoleMode

    #include <stdio.h>
    #include <stdlib.h>
    #include <termios.h>
    
    int
    main(int argc, char **argv)
    {
        struct termios oflags, nflags;
        char password[64];
    
        /* disabling echo */
        tcgetattr(fileno(stdin), &oflags);
        nflags = oflags;
        nflags.c_lflag &= ~ECHO;
        nflags.c_lflag |= ECHONL;
    
        if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) {
            perror("tcsetattr");
            return EXIT_FAILURE;
        }
    
        printf("password: ");
        fgets(password, sizeof(password), stdin);
        password[strlen(password) - 1] = 0;
        printf("you typed '%s'\n", password);
    
        /* restore terminal */
        if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {
            perror("tcsetattr");
            return EXIT_FAILURE;
        }
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought i could use the 'attributes' feature for this, but unfortunately the way
I could use another pair of eyes. This script does what I want in
I could use a bit of help with this, as i am new to
I know I could use PHP to do this, but wanted to find out
Could use some help. I am utterly stuck, been trying to fix this one
I thought I could use... studentID = myDataGid.selectedItem.studentID Does not want to work for
I really could use some help in the right direction with this. Thanks!
I could use some help on this problem. I'm creating an application using Symfony2
We could use [NSObject class] to get class object, but forgot how to get
I could use a little help. I got this program to work right then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.