Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'is this secure'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 1 result

  1. Hey, everyone Coding a small application with user authentication. Never done this before as I've not been secure enough regarding my abilities to create something secure. Regarding password security: My passwords are saved using double hashing. First, the users's email is hashed with the sha256 algorithm together with a site-wide salt using the function below. I then use the same hashing function to hash the user's password together with the unique salt. That means that password will differ for each user even if they use the same password. Don't mind the functionality of $mysqli->query(), etc. I use my own class. public function login( $email, $password ) { // Get DB connection $mysqli = new Database(); $mysqli->escape($email); $user = $mysqli->query("SELECT * FROM bet_users WHERE email = '$email' LIMIT 1"); // Get user from DB // Make sure we found a user ( An array ) if ( is_array($user) ) { // Get special hash $hash = $this->hash($email, HASH_SALT); // Site wide salt // Check hashed passwords if ( $user['password'] == $this->hash($password, $hash) ) // Hash $password with unique salt { // Prevent session hijack Util::validate_session($email); // Set user details $this->set_user_details($user); // User is logged in return true; } // Wrong password return false; } } private function hash( $input, $salt ) { // Initialize an incremental hashing context $hashed = hash_init('sha256', HASH_HMAC, $salt); // Set active hashing context hash_update($hashed, $input); // Return hashed password return hash_final($hashed); } Regarding login checks: I only add $_SESSION['admin'] to the session array if the queried user has admin status in the DB. My checks looks like this and uses the session hijacking check below. I use these function like Util::is_logged_in() and Util::is_admin(). public static function is_logged_in() { return isset($_SESSION['user_id']) && self::validate_session($_SESSION['email']); } public static function is_admin() { return self::is_logged_in() && isset($_SESSION['admin']) && $_SESSION['admin'] == true; } Here's the function to prevent session hijack: public static function validate_session( $email = null ) { // Set hashed http user agent $agent = md5($_SERVER['HTTP_USER_AGENT'].$email); // Check for instance if ( isset($_SESSION['initiated']) == false || isset($_SESSION['HTTP_USER_AGENT']) == false ) { // Create new id session_regenerate_id(TRUE); $_SESSION = array(); $_SESSION['initiated'] = true; // Set hashed http user agent $_SESSION['HTTP_USER_AGENT'] = $agent; } if ( isset($_SESSION['initiated']) && isset($_SESSION['HTTP_USER_AGENT']) ) { // Validate the agent and initiated if ( ($_SESSION['HTTP_USER_AGENT'] == $agent) && $_SESSION['initiated'] ) { return true; } else { // Destroy session session_destroy(); return false; } } return false; } How would you say the security is here? Is the security good? Any improvements I can make? Thanks for any answers.
×
×
  • Create New...