Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2005
    Posts
    49
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Password hashing?

    I have a cgi script written in c++ that interacts with a mysql database. My question is this: How can I, from the administrator html page, use sha1 to hash passwords as I add new users to the website?

    I'll be creating their usernames and passwords myself and was wondering if I could use a function such as sha1 (or something else?) to hash the password and then store it into the database. Any help would be greatly appreciated.

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Code:
    INSERT INTO
    yourtablename
    (userid, password, othercolumns)
    VALUES
    ('xxx',sha1('passwordhere'),'blah blah blah values')
    you then compare the SHA1 of the password they subsequently log in with and the stored password

    Code:
    SELECT count(*)
    FROM yourdatabase
    WHERE userid=$userid
    AND password = sha1('$password')
    if the count is 1 you let them in otherwise reject them.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •