Masking Password with *'s


 
Thread Tools Search this Thread
Top Forums Programming Masking Password with *'s
# 8  
Old 12-15-2010
Quote:
Originally Posted by bigdrock44
I'm actually getting the same results as the first code you posted. I was wondering, would getc() and putc() work? I thought getc() didn't echo and I could basically do a loop using getc(stdin) and putc('*', stdout). I could never get it to work though...
It's nothing to do with what function you use because your terminal device is configured to echo and line-buffer. The echoing and buffering isn't happening anywhere in your code -- it happens in the operating system itself. You have to tell it not to do that.

But stdio isn't prepared to read from a raw terminal, since they act rather strange. So, once you change the terminal settings, you need to read from it with a low-level read().
# 9  
Old 12-16-2010
@jim: I used your exact code to test it before I implemented it and I couldn't get it to work.

@corona: So if it has to do with my terminal settings what setting do I need to change?
# 10  
Old 12-16-2010
I haven't tried your code, but this line bothers me:

Code:
term.c_cc[VMIN]=0;

Isn't that supposed to be 1 for what you're looking to do? Maybe your OS handles the 0 case differently from those systems that jim_mcnamara tested it with.

There is also no need for select().

Last edited by Driver; 12-16-2010 at 02:40 PM..
# 11  
Old 12-16-2010
Quote:
Originally Posted by bigdrock44
@corona: So if it has to do with my terminal settings what setting do I need to change?
Well, echo, of course, that must be turned off. And the minimum read size has to be set to zero. And to put it out of canon mode, which line buffers and such, into the raw mode which does what you want.

Or, in a nutshell: All the settings Jim changes.

Quote:
Originally Posted by Driver
There is also no need for select().
Strictly speaking, there's not. But since the terminal doesn't block in raw mode like this, it's way better than a CPU-sucking infinite read() loop. Other alternatives, like poll(), aren't portable.

I can't perfectly explain why, but 0 seems to work better than 1. with 1 it seems to block mysteriously.

Last edited by Corona688; 12-16-2010 at 11:54 PM..
# 12  
Old 12-17-2010
Quote:
Strictly speaking, there's not. But since the terminal doesn't block in raw mode like this, it's way better than a CPU-sucking infinite read() loop. Other alternatives, like poll(), aren't portable.

I can't perfectly explain why, but 0 seems to work better than 1. with 1 it seems to block mysteriously.
So you're saying 1 is the correct setting, right? Smilie We do want to block, reading one character at the time, and that's just normal behavior for noncanonical terminals unless you're using O_NONBLOCK.

The select() kludge is unneeded if you set c_cc[VMIN] properly.

Nowhere in the original question does the OP mention any wishes for timeouts of any sort.
# 13  
Old 12-17-2010
The terminal I'm using is pretty simple. I took a course in C/Unix last quarter and I'm using the terminal they had us use, which I'm sure is probably very basic since the class is aimed at engineers rather than computer science/computer programming majors. It's called SSH Secure Shell. Do you have any recommendations on maybe a more advanced terminal? FreeSmilie?
# 14  
Old 12-17-2010
Quote:
Originally Posted by bigdrock44
The terminal I'm using is pretty simple. I took a course in C/Unix last quarter and I'm using the terminal they had us use, which I'm sure is probably very basic since the class is aimed at engineers rather than computer science/computer programming majors. It's called SSH Secure Shell. Do you have any recommendations on maybe a more advanced terminal? FreeSmilie?
Having to change the terminal settings to get the behavior you want has nothing to do with your terminal client. Any terminal login you make, be it ssh, telnet, a hardwired local console, or even a serial port plugged into the machine, will behave much the same way as far as your program is concerned. That's the entire point of having the kernel manage them: It handles the raw I/O itself, and emulates any other low-level behavior necessary to make them communicate the same way as far as a program can see.

By default you get blocking mode with echo for the convenience of your program, since it's way more predictable, not to mention efficient when doing bulk data transfers. If you want raw mode, you change the kernel's terminal settings to get it.

---------- Post updated at 09:50 AM ---------- Previous update was at 09:35 AM ----------

Quote:
Originally Posted by Driver
So you're saying 1 is the correct setting, right? Smilie
No. By block mysteriously, I mean, block on more than one character even when vmin=1. I wasn't able to get "proper" behavior as you describe it, and don't want to give someone "compliant" yet broken code.
Quote:
We do want to block
You're only assuming that. The ability to detect when keystrokes are not happening is useful, why deny it to them?

Even assuming you're right, we want it to block at one character, no more. I couldn't get a terminal to honor that. It may not be portable either.

select() on the other hand can be trusted. It's also flexible enough to give us both options -- blocking, and timeouts, without changing the terminal settings further.

Quote:
The select() kludge
select() is not a kludge. It's a very efficient way to use a file descriptor. It also means getting the behavior you want without having to fight the the hugely complex and baroque terminal option structure.
Quote:
Nowhere in the original question does the OP mention any wishes for timeouts of any sort.
But it's handy to give them that option.

Last edited by Corona688; 12-17-2010 at 12:00 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Masking with gsub command

My file "test.dat" data as below Requirement is to mask(replace) all english characters with "X" EXCEPT first 7 characters of every line. my command awk '{gsub("]","X")}1' test.dat looks not working properly, Appreciate any suggestion... (6 Replies)
Discussion started by: JSKOBS
6 Replies

2. UNIX for Dummies Questions & Answers

Masking data

How Can I mask one particular columns using some unix command? (4 Replies)
Discussion started by: dsa
4 Replies

3. Shell Programming and Scripting

Masking algorithm

I have a requirement of masking few specific fields in the UNIX file. The details are as following- File is fixed length file with each record of 250 charater length. 2 fields needs to be masked – the positions are 21:30 and 110:120 The character by character making needs to be done which... (5 Replies)
Discussion started by: n78298
5 Replies

4. Shell Programming and Scripting

Masking Password from within a Bash Shell Script

Is there a way to mask the password inside of a script to minimize the impact of a comprimised server? So ssh -o "PasswordAuthentication no" -o "HostbasedAuthentication yes" -l testuser 192.168.3.1 "mysqldump --opt --all-databases -u root -pPassword| gzip" > $backup_dir/mysqldump.gz a... (2 Replies)
Discussion started by: metallica1973
2 Replies

5. Shell Programming and Scripting

masking issue

Hi I am facing an issue with the below script which has the below line each field being separated with a tab. I need to mask the 8 and 7th field based on following conditions 1. 8th field is 16 in length and is numerics i will mask the middle 6 digits except the first 6 and last 4. input... (2 Replies)
Discussion started by: mad_man12
2 Replies

6. Shell Programming and Scripting

Scripting help/advise on hiding/masking username/password

Hi, I currently have a UNIX script with a function that uses a username and password to connect to the database, retrieve some information and then exit. At the moment, am getting the username and password from a hidden plain text file and permission set to -r--------, i.e. read only to who... (1 Reply)
Discussion started by: newbie_01
1 Replies

7. Emergency UNIX and Linux Support

Masking of number

BAT:0310:2009-08-0:Y4 :H:D:00003721:03103721.IFH:00138770:05767:00000000001279' EXR:CLP:912.570000' STA:A:9071559:2009-08-10::Wer::Mrs' DEF::531.97:531.97:310221661617::+ABC:BAL:1:N::::5:40.00:0.00:2009-08-10:CN:1111111111109962::3:N:missc :N:PH:00010833:... (5 Replies)
Discussion started by: mad_man12
5 Replies

8. Shell Programming and Scripting

Data Masking

I have a pipe delimited file that I need to 'mask' to before loading to keep some data confidential. I need to maintain the first 4 bytes of certain columns and replace the remaining bytes with an 'x'. I would like to maintain spaces but it's not a requirement. Example, need to mask columns 2... (2 Replies)
Discussion started by: 1superdork
2 Replies

9. Shell Programming and Scripting

Masking Content of a String

Hello, I need to know that whether a content of a string can be hidden or masked inside a shell script. My Sample Code is given below <Code> #!/usr/bin/ksh Userid=test DB=temp Passwd=`java Decryption test` # The Above command will get the encryped password for "test" user id and store... (2 Replies)
Discussion started by: maxmave
2 Replies

10. IP Networking

IP Masking

Is it possible for a internal LAN to mask a IP e.g. i have a server ip running the intranet ip being 192.168.0.8 and i want to make that like www.intranet.com is this possible on a internal network ? (1 Reply)
Discussion started by: perleo
1 Replies
Login or Register to Ask a Question