Welcome Guest, Not a member yet? Register   Sign In
Is this code secure enough
#6

[eluser]veledrom[/eluser]
I'm sending plain PHP code without CI bits to reduce lines.

How do I validate user login if I use script below? I mean, since salt is dynamic how do I use in SELECT statement in VALIDATE USER LOGIN section below?

Thanks

Code:
<?php
/*
**
** DATABASE STRUCTURE **************************************************************
**
** CREATE TABLE `users` (
** `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
** `username` varchar(20) NOT NULL,
** `password` varchar(40) NOT NULL COMMENT 'encrypted password',
** `salt` varchar(20) NOT NULL COMMENT 'random key',
** PRIMARY KEY (`id`)
** );
**
*/


/*
** CREATE AN ACCOUNT IN DATABASE ***************************************************
*/

$username  = $_POST['username'];     //Get username from form
$password  = $_POST['password'];     //Get password from form

$ci_encryption_key = $this->config->item('encryption_key');  //Get CI's static key
$salt   = mt_rand();                 //Generate dynamic salt value
$hash   = sha1($ci_encryption_key . $password. $salt);  //Generate hash password

$sql = "INSERT INTO login (username, password, salt) VALUES ('" . $username . "', '" . $hash . "', '" . $salt . "')";


/*
** VALIDATE USER LOGIN *************************************************************
*/

$username  = $_POST['username'];     //Get username from form
$password  = $_POST['password'];     //Get password from form

$ci_encryption_key = $this->config->item('encryption_key');  //Get CI's static key

$sql = "SELECT username FROM login WHERE username = '" . $username . "' AND ?????????????????";


Messages In This Thread
Is this code secure enough - by El Forum - 03-05-2012, 04:48 AM
Is this code secure enough - by El Forum - 03-05-2012, 09:05 AM
Is this code secure enough - by El Forum - 03-05-2012, 09:42 AM
Is this code secure enough - by El Forum - 03-06-2012, 01:31 AM
Is this code secure enough - by El Forum - 03-06-2012, 07:31 AM
Is this code secure enough - by El Forum - 03-06-2012, 08:47 AM
Is this code secure enough - by El Forum - 03-06-2012, 09:10 AM
Is this code secure enough - by El Forum - 03-07-2012, 05:12 AM
Is this code secure enough - by El Forum - 03-07-2012, 10:17 AM
Is this code secure enough - by El Forum - 03-07-2012, 12:31 PM



Theme © iAndrew 2016 - Forum software by © MyBB