Reading a password


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading a password
# 1  
Old 09-29-2010
Reading a password

For an assignment i have to create a CSH menu that requires a password in order to login, and then does all this other stuff.

I am really stumped on the password part though here is the question

1) ask for a password from the user.
If the password is not correct, the system will exit
with an appropriate error message.

The program password file must be called "PASSWORD" in the current directory. The password will be in this file as a single newline-terminated word. For testing purposes, I will assume that this file will be part of your tgz submission. It also only requires the first 32 characters for varification.

Originally i had

Code:
echo "please enter the password: "
set password = $<

then a simple IF statement
Code:
if ( $password != whatever is in the file ) then
echo "password is incorrect"
exit

The problem is, i have no idea how to read from the PASSWORD file that we have to create.

I dont expect an answer to this specific problem, as i would much rather make it on my own, but any help regarding how to take text from a file to validate, and also how to just take the first 32 characters would be wonderful..

Cheers

---------- Post updated at 04:23 AM ---------- Previous update was at 04:10 AM ----------

Update:

I am now able to read from the file using this
Code:
echo "enter password"
stty -echo
set password = $<
stty echo
echo ""

set systemPassword = `cut -c 1-32 PASSWORD`

if ( $password != $systemPassword ) then
error

only problem is, my cutting of the first 32 characters doesnt work...
# 2  
Old 09-29-2010
Code:
echo "enter password"
systemPassword = $(cut -c 1-32 PASSWORD)
stty -echo
set password = $<
stty echo
echo ""
if ( $password != $systemPassword ) then
error

# 3  
Old 09-29-2010
Thanks man, it all seems to work now.

I do have a problem with updating the password though.
my code (within a case statement):
Code:
case passwd
  echo "enter old password"
  set pass = $<
    if ( $pass != $systemPassword ) then
      echo "password does not match"
   else
      echo "enter new password"
      set newPass = $<
      $newPass >PASSWORD
   endif
breaksw

I keep getting an error though
if i enter new password as "hello"
i get "hello: command not found."
# 4  
Old 09-29-2010
$newPass is Variable,so you will get "command not found"

Code:
case passwd
  echo "enter old password"
  set pass = $<
    if ( $pass != $systemPassword ) then
      echo "password does not match"
   else
      echo "enter new password"
      set newPass = $<
      echo "$newPass" >PASSWORD
   endif
breaksw

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

Password sent via reset password email is 'weak' and won't allow me to change my password

I was unable to login and so used the "Forgotten Password' process. I was sent a NEWLY-PROVIDED password and a link through which my password could be changed. The NEWLY-PROVIDED password allowed me to login. Following the provided link I attempted to update my password to one of my own... (1 Reply)
Discussion started by: Rich Marton
1 Replies

2. UNIX for Dummies Questions & Answers

Reading password from /dev/tty

hi, From the below script: ##########################################pwd_auth.sh######################################################################################## #Author: Pandeeswaran Bhoopathy #Written on:26th Jan 2012 2:00PM #This script describes the feature of stty and illustrates... (3 Replies)
Discussion started by: pandeesh
3 Replies

3. UNIX for Dummies Questions & Answers

password protect a CSV file: better solution than ZIP password?

Hi We send *.csv with sensitive data to our customers. Our customers open those files with Excel. A new requirement is that we password protect those CSV files. I thought to pack them with ZIP and assign a password to the archive. But Solaris 10 can't encrypt ZIP files. $ zip -P... (12 Replies)
Discussion started by: slashdotweenie
12 Replies

4. HP-UX

reading password and echoing '*' character on console

hi all, I am using HP-UX system. I want echoing * characters while reading password through keyboard instead of blank space. can u help me for that code? Thanks (1 Reply)
Discussion started by: hari_uctech
1 Replies

5. Shell Programming and Scripting

how to change root password using shell script with standard password

Hi Friends. I am new to scripting now i want to change the root password using the script with standard password. which is the easy scripting to learn for the beginner, Thanks in advance. (2 Replies)
Discussion started by: kurva
2 Replies

6. UNIX for Advanced & Expert Users

password verification verify password of a user for only first 8 characters

Helo , I m using linux pam library for user and its password authentication. I m creating new user and giving its password.I m giving password of 10 characters.now when I login in as that newly created user its ask me $ su - ram Password: You are required to change your password immediately... (12 Replies)
Discussion started by: amitpansuria
12 Replies

7. Shell Programming and Scripting

Reading password and echo * character

Hi, First of all i am using solaris 10. I want to write a script that ask user to enter password and read the character input from keyboard. The ask to re-enter the password and then if they are match it will accept. But my problem is I want to echo a '*' character instead of the character I... (4 Replies)
Discussion started by: alanpachuau
4 Replies

8. Programming

reading reading data from webpage

hi iam reading data from web page using request socket and curl socket. now my problem is some the web page containg data as a image so how can i read the data from a image. thank,inadvance. sree (3 Replies)
Discussion started by: phani_sree
3 Replies

9. Shell Programming and Scripting

Script for Reading a Password file

How do I Authenticate users with a Password file that I have build using PWP - Password Privacy Password file contents are as under bash-2.03$ cat passwd.cf janes hostname Q+BejYC7AxGVv21TiAiUYQ== user janes /tmp/pwp_access.cf Now two things I need from a script If the... (2 Replies)
Discussion started by: srirams
2 Replies
Login or Register to Ask a Question