+ Reply to Thread
Results 1 to 10 of 10

Thread: Unix Shell Password Check

  1. #1
    kbjradmin's Avatar
    kbjradmin is offline x10 Elder kbjradmin is an unknown quantity at this point
    Join Date
    Feb 2008
    Location
    Washington State, USA
    Posts
    512

    Unix Shell Password Check

    I am writing a script to lock a unix system but not logout.
    When the script is run, I want it to provide a prompt for the user to enter their password to unlock the system.

    How can I check this to make sure it is their password?

  2. #2
    woiwky is offline x10 Lieutenant woiwky is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    390

    Re: Unix Shell Password Check

    Assuming there's more than one user, you'll need to use some form of a database. A flat-file db would work fine, but a db like mysql could work as well. With a flat-file db, you'll need to look for a username/password match in the file. With mysql, you'll need to execute a query such as:

    mysql -u username -p password -D database -e "SELECT id FROM users WHERE password = '$password' AND username = '$username'"

    And as for making the password not show up as they type, use 'stty -echo' before the prompt to enter data. You should then use 'stty echo' after they enter it to show the typed characters in further prompts.
    "But you have access to the greatest source of knowledge in the universe."
    "Well I do talk to myself sometimes, yes."

    "I'm back, and I'm bad! Obviously within certain, sensible, preset parameters"

  3. #3
    kbjradmin's Avatar
    kbjradmin is offline x10 Elder kbjradmin is an unknown quantity at this point
    Join Date
    Feb 2008
    Location
    Washington State, USA
    Posts
    512

    Re: Unix Shell Password Check

    thank you woiwky. that's very helpful.

    i'm new to unix, so i'm not sure; but will the sql query check for the users unix password, or is that for some other password, because i was not aware that unix used sql for it login information.
    Last edited by kbjradmin; 01-18-2009 at 01:06 PM.

  4. #4
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: Unix Shell Password Check

    that would be a password stored in the db. unix stores the user's passwords somewhere in the /etc/ folder (i think it's /etc/passwd or /etc/shadow, but i could be wrong). a google search should come up helpful
    Last edited by xPlozion; 01-18-2009 at 02:00 PM.

  5. #5
    woiwky is offline x10 Lieutenant woiwky is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    390

    Re: Unix Shell Password Check

    I think I see what you mean now. I was a little confused. You want to use the unix login info for this then?

    In this case, like xPlozion said, you'll have to use the password file which is probably in /etc/passwd. If they're in /etc/shadow, then this makes it harder because the user needs the privilege to access this file. You could give all the users this privilege, but that will negate the security gain of having the data stored there.

    In any case, you'll need to encrypt(crypt(3) I believe) the password they enter before comparing it to the value in the file. I'm not 100% sure about this part, but if you do a little research I'm sure you'll find the answer.

    Once you have the encrypted password, it's as easy as comparing it to the data in the file.
    "But you have access to the greatest source of knowledge in the universe."
    "Well I do talk to myself sometimes, yes."

    "I'm back, and I'm bad! Obviously within certain, sensible, preset parameters"

  6. #6
    dbojan's Avatar
    dbojan is offline x10Hosting Member dbojan is an unknown quantity at this point
    Join Date
    Nov 2008
    Location
    Bosnia and Herzegovina
    Posts
    99

    Re: Unix Shell Password Check

    The password of *nix users is stored in /etc/shadow and it's crypted and i don't think you can use crypt to see password, because everyone could do that and have your password. You probably need some api function, google will help you.

  7. #7
    woiwky is offline x10 Lieutenant woiwky is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    390

    Re: Unix Shell Password Check

    The passwords cannot be decrypted, but they can be compared to another encrypted password for verification. How else would you be able to login?
    "But you have access to the greatest source of knowledge in the universe."
    "Well I do talk to myself sometimes, yes."

    "I'm back, and I'm bad! Obviously within certain, sensible, preset parameters"

  8. #8
    kbjradmin's Avatar
    kbjradmin is offline x10 Elder kbjradmin is an unknown quantity at this point
    Join Date
    Feb 2008
    Location
    Washington State, USA
    Posts
    512

    Re: Unix Shell Password Check

    thank you, everyone; i think i understand now.

  9. #9
    dbojan's Avatar
    dbojan is offline x10Hosting Member dbojan is an unknown quantity at this point
    Join Date
    Nov 2008
    Location
    Bosnia and Herzegovina
    Posts
    99

    Re: Unix Shell Password Check

    @woiwky dude it's not like php. In php we have only one way crypting. But in *nix we have crypt and decrypt so it would be easy to find password if it's like you said.

  10. #10
    woiwky is offline x10 Lieutenant woiwky is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    390

    Re: Unix Shell Password Check

    Quote Originally Posted by dbojan View Post
    @woiwky dude it's not like php. In php we have only one way crypting. But in *nix we have crypt and decrypt so it would be easy to find password if it's like you said.
    Do you understand what the topic here is(or was)? There's no php involved. Although I will say that php certainly provides more than one method of encryption.

    Furthermore, even if a password is encrypted, as long as the encryption algorithm is known, it is possible to compare passwords. This is how a typical login system works.

    Yes, the same process could be used for cracking passwords, and it is easy to setup, but it is not an easy method of cracking passwords(this is called brute force cracking by the way). Unless the password is weak, it would take far too long to crack in most cases.
    "But you have access to the greatest source of knowledge in the universe."
    "Well I do talk to myself sometimes, yes."

    "I'm back, and I'm bad! Obviously within certain, sensible, preset parameters"

+ Reply to Thread

Similar Threads

  1. An email from own domain issue
    By holeepassion in forum Free Hosting
    Replies: 5
    Last Post: 02-08-2008, 06:35 PM
  2. Regarding cPanel Password
    By coolnos in forum Free Hosting
    Replies: 4
    Last Post: 02-05-2008, 05:16 PM
  3. how to password protect your folder
    By agaitu in forum Tutorials
    Replies: 6
    Last Post: 12-14-2007, 04:03 PM
  4. What is Authentication
    By asadislam78 in forum Computers & Technology
    Replies: 1
    Last Post: 12-13-2007, 07:13 AM
  5. Wordpress Database Password Problem
    By roropheno in forum Free Hosting
    Replies: 8
    Last Post: 12-08-2007, 03:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers