LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-27-2008, 06:22 AM   #1
dolphs
Member
 
Registered: Nov 2003
Posts: 52

Rep: Reputation: 15
hiding typed text with asterisks


Hi gurus,

In a (korn)-script the following line is put

" echo "password: "; read INPUT; if [ "" != "$INPUT" ]; then PASS=$INPUT; fi "

My aim is to hide the characters typed in on the screen as it will show ones password ;D, how to achieve this please?


Looking forward to hearing from you.

Last edited by dolphs; 08-27-2008 at 06:25 AM.
 
Old 08-27-2008, 07:18 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
In a terminal, you can use stty to turn off echoing. Just remember to turn it on again afterwards.

Code:
#!/bin/bash

get_password () {
    stty -echo
    read -p "${1:-password}: " pass
    stty echo
    echo "" 1>&2
    echo "$pass"
}

p1=$(get_password "enter a password")
p2=$(get_password)

echo p1 is $p1
echo p2 is $p2
 
Old 08-27-2008, 07:28 AM   #3
dolphs
Member
 
Registered: Nov 2003
Posts: 52

Original Poster
Rep: Reputation: 15
Cheers for your response - so having a korn script with these lines how to implement it properly

echo "login name: "; read INPUT; if [ "" != "$INPUT" ]; then LOGIN=$INPUT; fi # this input needs to be shown on terminal
echo "password: "; read INPUT; if [ "" != "$INPUT" ]; then PASS=$INPUT; fi # input needs to be replaced with '*' on terminal
 
Old 08-27-2008, 07:34 AM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Oh, I think ksh doesn't support the -p option to read, but that's just a nicety of bash - you can simply echo the prompt, although you should send it to stderr to prevent line buffering fro hiding it until after the function completes.
Code:
#!/bin/ksh

get_password () {
    echo -n "${1:-password}: " 1>&2
    stty -echo
    read pass
    stty echo
    echo "" 1>&2
    echo "$pass"
}

p1=$(get_password "enter a password")
p2=$(get_password)

echo p1 is $p1
echo p2 is $p2
 
Old 08-27-2008, 07:42 AM   #5
dolphs
Member
 
Registered: Nov 2003
Posts: 52

Original Poster
Rep: Reputation: 15
cheers again but I am a little lost in the dark...

./script_test.sh

login name:
jdoe

enter a password:
password:
p1 is nostar
p2 is noway
 
Old 08-27-2008, 08:07 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Look at this post and see if it works for you. Change the interpreter from bash to ksh and strip out the -p option from the read statement, since it is not supported by ksh (as matthewg42 already pointed out) or better it has a different behaviour. For example you can substitute:
Code:
read -p "please enter username and press [enter]: " username
with
Code:
echo -n "please enter username and press [enter]: "
read username

Last edited by colucix; 08-27-2008 at 08:10 AM.
 
Old 08-27-2008, 08:07 AM   #7
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Stars no. Removing echo - yes.

Stars are a bad idea anyhow - some shoulder surfer who sneaks a peak at your fingers as you type can get extra information by counting how many characters you typed by looking as the asterisks, to validate when he thinks you typed - why give them that extra information?

The only use for asterisks which I can think of is where the password is a fixed length pin and the keys do not provide good tactile feedback - e.g. an ATM. For regular computer passwords, I think they are not a good idea.

Furthermore, AFAIK the shell doesn't provide a mechanism to do this - you can't detect raw key presses because the shell is line buffered. Either the terminal echos the typed input, or it does not.

You could write a small program to get the password with some language which direct character access to the keyboard.
 
Old 08-27-2008, 08:15 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by matthewg42 View Post
Stars are a bad idea anyhow - some shoulder surfer who sneaks a peak at your fingers as you type can get extra information by counting how many characters you typed by looking as the asterisks
A trained eye behind your shoulder could read the password from your key presses!
 
Old 08-27-2008, 08:25 AM   #9
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
That reminds me of something I saw a long time ago. A Lotus Notes installation at a place I once worked did something strange when users entered their passwords... It displayed four little graphics. No asterisks, but instead these little graphics in the four corners of the password entry box.

The choice of these icons seemed somehow deterministic - with the correct password, the same icons would always be visible at the end of the entry.

Does anyone know the rationale behind this? I assumed it was some sort of confirmation that user has not fat-fingered their password, but it seems like a silly idea to me.... It occurred to me that if the icons displayed were somehow deterministic based on the entry so far, wouldn't a simple video recording of the screen as the password was entered allow an attacker to verify each keypress?

Weird!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers names with one and two asterisks? hubabuba Programming 3 03-19-2006 04:00 PM
font + asterisks password childish Linux - Newbie 9 06-24-2005 03:24 PM
converting string to asterisks pantera Programming 2 09-13-2004 01:27 PM
How to search for asterisks using gawk dtheorem Linux - General 1 03-05-2004 02:35 PM
Linux...Modems...Asterisks PBX tadd Linux - Hardware 0 12-02-2003 08:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration