Closed lilveniceguy closed 8 years ago
Can others login?
Are the password hashes being created in the DB?
Are you seeing any PHP errors when creating the user or when logging in?
Thanks for answer!
I'm creating the user with this script:
public function creaUsuario(){
$username = 'jlopez';
$password = 'adminadmin';
$email = 'jose@moovmedia.cl';
$additional_data = array(
'first_name' => 'jose',
'last_name' => 'Lopez',
'perfil' => '20393'
);
$group = array('1','2','4','5','6','7','8','9','10','11','12','13','14'); // Sets user to admin. No need for array('1', '2') as user is always set to member by default
//1 admin
//2 respaldo
//5 a 14 empresa
if($this->ion_auth->register($username, $password, $email, $additional_data, 1)){
$messages = $this->ion_auth->messages_array();
foreach ($messages as $message)
{
echo $message;
}
echo "
usuario creado";
}else{
$errors = $this->ion_auth->errors_array();
foreach ($errors as $error)
{
echo $error;
}
echo $error."
error creando usuario
".$username.', '.$password.', '.$email.', '.$additional_data;
}
}
And no, I'm not seeing any PHP errors, the user is created on the db, but when I'm login it doesn't work.
Login function:
public function ingresar(){ $identity = $this->input->post('usuario'); $password = $this->input->post('clave'); $remember = FALSE; // remember the user //var_dump($this->session->all_userdata());exit; //var_dump($this->ion_auth->logged_in());exit; if ($this->ion_auth->logged_in()) { redirect('eicl/administracion'); } else { $data['error'] = "Usuario o clave incorrectos."; $this->load->view('header'); $this->load->view('login',$data); $this->load->view('footer'); } }
You're not calling login() in your controller. Try this:
public function ingresar(){ $identity = $this->input->post('usuario'); $password = $this->input->post('clave'); $remember = FALSE; // remember the user //var_dump($this->session->all_userdata());exit; //var_dump($this->ion_auth->logged_in());exit; if ($this->ion_auth->login()) { redirect('eicl/administracion'); } else { $data['error'] = "Usuario o clave incorrectos."; $this->load->view('header'); $this->load->view('login',$data); $this->load->view('footer'); } }
Nothing, I put it this way:
public function ingresar(){
$identity = $this->input->post('usuario');
$password = $this->input->post('clave');
$remember = FALSE; // remember the user
//var_dump($this->session->all_userdata());exit;
//var_dump($this->ion_auth->login());exit;
if ($this->ion_auth->login($identity, $password, $remember))
{
redirect('eicl/administracion');
} else {
$data['error'] = "<strong style='color:red;'>Usuario o clave incorrectos.</strong>";
$this->load->view('header');
$this->load->view('login',$data);
$this->load->view('footer');
}
}
But the same result, incorrect user or password, is there any way that encrypting is different for login and register?
No it's shared. What does:
var_dump($this->ion_auth->login());exit;
Give you?
Bool(false)
What do the following return:
var_dump($this->ion_auth->messages());
var_dump($this->ion_auth->errors());
string(0) "" string(22) " Incorrect Login
"
This is weird. No the hashing will be the same.
Post your config and the query results of the user record in the DB.
Config.php:
<?php
$config['base_url'] = '';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = FALSE;
$config['subclassprefix'] = 'MY';
$config['permitted_urichars'] = 'a-z 0-9~%.:-';
$config['allow_get_array'] = TRUE; $config['enable_query_strings'] = FALSE; $config['controller_trigger'] = 'c'; $config['function_trigger'] = 'm'; $config['directory_trigger'] = 'd'; // experimental not currently in use
$config['log_threshold'] = 1;
$config['log_path'] = '';
$config['log_date_format'] = 'Y-m-d H:i:s';
$config['cache_path'] = '';
$config['encryption_key'] = '7e04da88cbb8cc933c7b89fbfe121cca';
$config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 7200; $config['sess_expire_on_close'] = FALSE; $config['sess_encrypt_cookie'] = FALSE; $config['sess_use_database'] = TRUE; $config['sess_table_name'] = 'ci_sessions'; $config['sess_match_ip'] = FALSE; $config['sess_match_useragent'] = FALSE; $config['sess_time_to_update'] = 300;
$config['cookie_prefix'] = ""; $config['cookie_domain'] = ""; $config['cookie_path'] = "/"; $config['cookie_secure'] = FALSE;
$config['global_xss_filtering'] = FALSE;
$config['csrf_protection'] = FALSE; $config['csrf_token_name'] = 'csrf_test_name'; $config['csrf_cookie_name'] = 'csrf_cookie_name'; $config['csrf_expire'] = 7200;
$config['compress_output'] = FALSE;
$config['time_reference'] = 'local';
$config['rewrite_short_tags'] = FALSE;
$config['proxy_ips'] = '';
?>
ion_auth.php:
<?php
$config['tables']['users'] = 'users'; $config['tables']['groups'] = 'groups'; $config['tables']['users_groups'] = 'users_groups'; $config['tables']['login_attempts'] = 'login_attempts';
$config['join']['users'] = 'user_id'; $config['join']['groups'] = 'group_id';
$config['hash_method'] = 'sha1'; // sha1 or bcrypt, bcrypt is STRONGLY recommended $config['default_rounds'] = 8; // This does not apply if random_rounds is set to true $config['random_rounds'] = FALSE; $config['min_rounds'] = 5; $config['max_rounds'] = 9; $config['salt_prefix'] = '$2y$';
$config['site_title'] = "Example.com"; // Site Title, example.com $config['admin_email'] = "admin@example.com"; // Admin Email, admin@example.com $config['default_group'] = 'members'; // Default group, use name $config['admin_group'] = 'admin'; // Default administrators group, use name $config['identity'] = 'email'; // You can use any unique column in your table as identity column. The values in this column, alongside password, will be used for login purposes $config['min_password_length'] = 8; // Minimum Required Length of Password $config['max_password_length'] = 20; // Maximum Allowed Length of Password $config['email_activation'] = FALSE; // Email Activation for registration $config['manual_activation'] = FALSE; // Manual Activation for registration $config['remember_users'] = TRUE; // Allow users to be remembered and enable auto-login $config['user_expire'] = 86500; // How long to remember the user (seconds). Set to zero for no expiration $config['user_extend_on_login'] = FALSE; // Extend the users cookies every time they auto-login $config['track_login_attempts'] = FALSE; // Track the number of failed login attempts for each user or ip. $config['track_login_ip_address'] = TRUE; // Track login attempts by IP Address, if FALSE will track based on identity. (Default: TRUE) $config['maximum_login_attempts'] = 5; // The maximum number of failed login attempts. $config['lockout_time'] = 600; // The number of seconds to lockout an account due to exceeded attempts $config['forgot_password_expiration'] = 0; // The number of milliseconds after which a forgot password request will expire. If set to 0, forgot password requests will not expire.
$config['remember_cookie_name'] = 'remember_code'; $config['identity_cookie_name'] = 'identity';
$config['use_ci_email'] = FALSE; // Send Email using the builtin CI email class, if false it will return the code and the identity $config['email_config'] = array( 'mailtype' => 'html', );
$config['email_templates'] = 'auth/email/';
$config['email_activate'] = 'activate.tpl.php';
$config['email_forgot_password'] = 'forgot_password.tpl.php';
$config['email_forgot_password_complete'] = 'new_password.tpl.php';
$config['salt_length'] = 22; $config['store_salt'] = FALSE;
$config['delimiters_source'] = 'config'; // "config" = use the settings defined here, "form_validation" = use the settings defined in CI's form validation library $config['message_start_delimiter'] = '
'; // Message start delimiter $config['message_end_delimiter'] = '
'; // Message end delimiter $config['error_start_delimiter'] = ''; // Error message start delimiter $config['error_end_delimiter'] = '
'; // Error message end delimiter/* End of file ionauth.php / /_ Location: ./application/config/ion_auth.php */ ?>
Database record:
id
, ip_address
, username
, password
, salt
, email
, activation_code
, forgotten_password_code
, forgotten_password_time
, remember_code
, created_on
, last_login
, active
, first_name
, last_name
, company
, phone
, perfil
53, '', 'jlopez', 'EWQqPlQ79ztxmJSmasAiBe36fd22627d4ab07c10', NULL, 'jose@moovmedia.cl', NULL, NULL, NULL, NULL, 1446958843, 1446958843, 1, 'jose', 'Lopez', NULL, NULL, '20393'
Have you changed any of the hashing config settings since this user was created?
If you try logging in the user in the same method as you registered them do you get the same?
I'd changed from sha1 to bcrypt and the salt_prefix but anytime I do this, I deleted and create the user again and always get the same :/
It's me again, what means activegroup? how do I know if my users belong to this? could this be the trouble?
is on database.php in my config folder:
$active_group = 'eidenuncias'; $active_record = TRUE;
No, I did check and is just for the db array, where can i find the function where this is recorded on the db? on the ion_auth_model.php?
Another clue:
In my table "login_attemps" isn't any register :/ not even an error or something
You have this comment:
" | store_salt: Should the salt be stored in the database? | This will change your password encryption algorithm, | default password, 'password', changes to | fbaa5e216d163a02ae630ab1a43372635dd374c0 with default salt."
But when I activate this and create the user with the "password" password encrypt like this: $2a$08$WB6ULiRlHc5vl/TdjzF7u.nq/58oUWd3BEmcjsYBTHr3ck82oyE3i
I put the default ion_auth.php
I'm using echo $this->bcrypt->hash('passsword');die; in my login function, and the encrypted pass is always different... It can't work this way, now I understand less hahaha
Bcrypt uses a random salt so the password will be unique each time the hash is created. So this is the expected result.
Hi! I change the call to the function made by the other programmer eicl/ingresar for auth/login and it works :/ I don't understand what is wrong with the first one
Can you post a diff?
This is the code in eicl/ingresar:
public function ingresar(){
$identity = $this->input->post('usuario');
$password = $this->input->post('clave');
$remember = (bool) $this->input->post('remember'); // remember the user
//var_dump($this->session->all_userdata());exit;
/_var_dump($this->ion_auth->login($identity, $password, FALSE));
var_dump($this->ion_auth->messages());
var_dump($this->ionauth->errors());exit;/
//echo $this->bcrypt->hash($password);die;
if ($this->ion_auth->login($identity,$password, $remember))
{
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect('eicl/administracion', 'refresh');
} else {
$data['error'] = "Usuario o clave incorrectos.";
//var_dump($this->ion_auth->errors());exit;
$this->load->view('header');
$this->load->view('login',$data);
$this->load->view('footer');
}
}
And this is on auth/login:
function login() { $this->data['title'] = "Login";
//validate form input
$this->form_validation->set_rules('identity', 'Identity', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == true)
{
//check to see if the user is logging in
//check for "remember me"
$remember = (bool) $this->input->post('remember');
//echo $this->input->post('identity').','. $this->input->post('password').','. $remember;
//echo $this->bcrypt->hash('password');die;
if ($this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $remember))
{
//if the login is successful
//redirect them back to the home page
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect('eicl/administracion', 'refresh');
}
else
{
//if the login was un-successful
//redirect them back to the login page
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect('auth/login', 'refresh'); //use redirects instead of loading views for compatibility with MY_Controller libraries
}
}
else
{
//the user is not logging in so display the login page
//set the flash data error message if there is one
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->data['identity'] = array('name' => 'identity',
'id' => 'identity',
'type' => 'text',
'value' => $this->form_validation->set_value('identity'),
);
$this->data['password'] = array('name' => 'password',
'id' => 'password',
'type' => 'password',
);
$this->_render_page('auth/login', $this->data);
}
}
In the first one I'm getting the variables validated and the second one validate on the script.
Huh, thanks for tracking it!
Hi! I'd never had worked with your class, someone is having trouble with his system and is asking for my help.
I'd check your function to create user and used it, created a user and try to login, but I can't login, can you help me in anyway?
I really appreciate any comment, thanks.
PD: Sorry for my bad english