473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Hiding Password


I have created a console based application using C# which asks for the user identification to work using that system. Now, the problem is that i'm not able to hide or encrypt the password on the screen. I want to make it like "LINUX" in which only the user name is shown to the user and not the password. Can you provide some information on how I can implement this thing using C# (Remember it's a console based application)?

Nov 15 '05 #1
1 6875
The console is created by default in line input mode. To do what you want to
do you need to use GetConsoleMode and SetConsoleMode to turn off line input
mode and character echo. The following is a quick and dirty example(watch
for line wrap):

using System;

namespace Whatever
{
class Class1
{
[System.Runtime.InteropServices.DllImport("kernel32 ")]
private static extern int SetConsoleMode(IntPtr hConsoleHandle,
int dwMode);

[System.Runtime.InteropServices.DllImport("kernel32 ")]
private static extern int GetConsoleMode(IntPtr hConsoleHandle,
ref int dwMode);

private const int ENABLE_LINE_INPUT = 2;
private const int ENABLE_ECHO_INPUT = 4;

private const int CONIN = 3;

[STAThread]
static void Main(string[] args)
{

IntPtr hStdIn = new IntPtr(CONIN);
int mode;
char inputChar;
string userName = null;
string password = "";

Console.WriteLine("Please enter your user name:");
userName = Console.ReadLine();

Console.WriteLine("Please enter your password:");

//Set console mode to read a character
//at a time and not echo input.
GetConsoleMode(hStdIn, ref mode);
mode = (mode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT));
SetConsoleMode(hStdIn, mode);

//Read the password a character at a time.
do
{
inputChar = (char)Console.Read();
if (inputChar >= 32)
{
//Echo character with password mask.
password += inputChar;
Console.Write("*");
}
} while (inputChar != '\r');//Enter pressed end of password.

//Set console back to line input
//mode if that's what you want.
//mode = (mode | (ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT));
//SetConsoleMode(hStdIn, mode);

Console.WriteLine("");

if (password == "Let me in")
{
Console.WriteLine("Welcome " + userName);
}
else
{
Console.WriteLine("Sorry, " + userName);
}
Console.Write("Press any key to continue...");
Console.Read();

}
}
}

"Nitin" <ni*********@hotmail.com> wrote in message
news:34**********************************@microsof t.com...

I have created a console based application using C# which asks for the user identification to work using that system. Now, the problem is that i'm
not able to hide or encrypt the password on the screen. I want to make it
like "LINUX" in which only the user name is shown to the user and not the
password. Can you provide some information on how I can implement this thing
using C# (Remember it's a console based application)?

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mikko | last post by:
I would like to do this html/file1.php cgi-bin/file2.php it is called: file1.php$c1=something file1.php is:
1
by: Jaque Moreau | last post by:
Hello, for applying via email I want to put my application folder online. But because I am disabled I am afraid of beeing phoned or mailed by weird nazis. Is it safe (at least for some...
10
by: Picho | last post by:
Hi all, Lets say I have a "secret" I wish to "hide", lets say a database password. For the more detailed problem, a web application/service that uses a connection string. all the solutions I...
11
by: Lorenzo Villari | last post by:
I premise I don't know C++ well but... I wondered what is this data hiding thing... I mean, if I can look at the header (and i need it beacuse of the class), then what's hidden? Can someone give...
4
by: sam | last post by:
Hi, Is there any way I can prevent people use some binary disambler (eg. strings in unix) to view the const string value in a compiled C++ program? Sam.
2
by: Hernán Freschi | last post by:
Hi all, I'm still working on my Caller ID software. As it sits in the traybar and basically does nothing, after a few minutes the screen saver kicks in and it still works, but I have to go move...
11
by: CodeLeon | last post by:
Hi. I would like to create a keylogger, are there any good tutorials? Also, more importantly, how do i hide this process from the task manager? NO, i am not a virus writer, so PLEASE no messages...
3
by: rudeman76 | last post by:
Hi, I have a form that has no menu bar (so people cannot go playing) and when the admin presses the admin button they have to enter in a password. After they enter in the password the menubar...
4
by: =?Utf-8?B?SHVleQ==?= | last post by:
I need to hide the new window started from the code below. If I run as is, the window is visible. If I comment out the code that sets a different user, domain, and password the window is hidden...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.