Invalid user name and password in magento admin - php

After comment in C:\xampp\htdocs\magento\app\code\core\Mage\Core\Model\Session\Abstract in varien.php
$cookieParams = array(
'lifetime' => $cookie->getLifetime(),
'path' => $cookie->getPath()
//'domain' => $cookie->getConfigDomain(),
//'secure' => $cookie->isSecure(),
//'httponly' => $cookie->getHttponly()
);
still it shows invalid username and password.
May i know any other way to fix this?
Thanks in advance.

Go to your phpmyadmin
Look for table admin_user
Click on user_id 1
then enter your new password with MD5 function
now go to admin login use username with newly created password..
don't forget to like my answer if it was helpful

Create the file structure
C:\xampp\htdocs\magento\app\code\local\Mage\Core\Model\Session\Abstract
then and do these changes
$cookieParams = array(
'lifetime' => $cookie->getLifetime(),
'path' => $cookie->getPath()
'domain' => $cookie->getConfigDomain(),
'secure' => $cookie->isSecure(),
//'httponly' => $cookie->getHttponly()
);

You can also temporarily overwrite the loginAction() function to create a new user upon hitting your admin page. This creates a user named "username" with a password of "password" you can change these to whatever you would like. If you still can't login after using this. Then I have a few other things to try.
Open /app/code/core/Mage/Adminhtml/controllers/indexController.php
Replace Temporarily the function loginAction
public function loginAction()
{
//Zend_Debug::dump(Mage::getSingleton('admin/session'));
if (Mage::getSingleton('admin/session')->isLoggedIn()) {
$this->_redirect('*');
return;
}
$loginData = $this->getRequest()->getParam('login');
$data = array();
if( is_array($loginData) && array_key_exists('username', $loginData) ) {
$data['username'] = $loginData['username'];
} else {
$data['username'] = null;
}
try
{
$user = Mage::getModel("admin/user")
->setUsername('username')
->setFirstname('Developer')
->setLastname('Forgot')
->setEmail('support#mysite.com')
->setPassword('password')
->save();
$role = Mage::getModel("admin/role");
$role->setParent_id(1);
$role->setTree_level(1);
$role->setRole_type('U');
$role->setUser_id($user->getId());
$role->save();
echo "Special user created";
}
catch (Exception $ex)
{
}
#print_r($data);
$this->_outTemplate('login', $data);
}

Related

code igniter session destroyed

Why codeigniter session destroyed after page re direction,
this is my auto load conf
$autoload['libraries'] = array('database','form_validation','session');
my login controller code is
$result = $this->Loginmodel->verify_user($this->input->post('username'), $this->input->post('password'));//returned as db->result()
if ($result !== False) {
//person has an account
foreach ($result as $obj) {
$user_id = $obj->user_id;
$userdesignation = $obj->user_designation;
$user_access = $obj->user_cpanelpass;
}
$sessiondata = array(
'user_id' => $user_id,
'username' => $username,
'loginuser' => TRUE,
'userdesignaton' => $userdesignation,
);
$this->session->set_userdata($sessiondata);
$sessiondata1 = array(
'shopname' => 'abc',
'shopplace' => 'xyz'
);
$this->session->set_userdata($sessiondata1);
$ipaddress = $this->ipaddress();
$this->Loginmodel->loginloginsert($username, $ipaddress);
redirect('home');
this is working fine in my system but not working in another system .The session is destroyed automatically when redirected to home or any other controller.

how to check a value of variable/data in codeigniter controller

i want to ask how do i check/see the value inside of this $datame in my code, i tried to var_dump it, i am using mozilla, it didn't show the value in console/network . Where or how do i check if there were data stored in my variable array.
public function facebook_request(){
$this->load->library('facebook/src/facebook', array('appId' => '1027885817316593', 'secret' => '6db175699897b514bf4881955b2944bb'));
$this->user = $this->facebook->getUser();
if ($this->user) {
$data['user_profile'] = $this->facebook->api('/me?fields=id,first_name,last_name,email,link,gender,locale,picture');
// Get logout url of facebook
$data['logout_url'] = $this->facebook->getLogoutUrl(array('next' => base_url() . 'index.php/oauth_login/logout'));
$datame = array(
'oauth_provider'=> 'facebook',
'oauth_uid' => $data['user_profile']['id'],
'first_name' => $data['user_profile']['first_name'],
'last_name' => $data['user_profile']['last_name'],
'email' => $data['user_profile']['email'],
'gender' => $data['user_profile']['gender'],
'locale' => $data['user_profile']['locale'],
'picture' => $data['user_profile']['picture']['data']['url'],
'link' => $data['user_profile']['link']
);
$userData = $this->user_model->checkUser2($datame);
var_dump($datame);
exit();
// Send data to profile page
$this->load->view('admin/profile.php', $data);
}
The server doesn't have access to write to that. You could pass $datame to the view you are trying to render and print it there or you could replace var_dump($datame) with error_log($datame) and then view your error log to see what it printed
change from
$userData = $this->user_model->checkUser2($datame);
var_dump($datame);
exit();
to
echo "<pre>";
print_r($datame);
exit();
$userData = $this->user_model->checkUser2($datame);

How to Redirect a URL to another URL if user is not Logged in: Codeigniter

I have a directory out side the app folder as this localhost/myproject/director
i want to made a redirection for this directory. if someone is not logged in and direct access this directory so it will be redirected to home page.
i have tried this but nothing works:
if(!$_SESSION['login']){
header("location:index.php");
die;
}
Assume your Session is set like this
$newdata = array(
'username' => 'johndoe',
'email' => 'johndoe#some-site.com',
'logged_in' => TRUE
);
So to check
if(logged_in == TRUE)
{
# logged User
$this->load->view("homepage");
}
else{
#not logged User
redirect("Login"); # set login controller name
}
For Your Information
If User Log once then set session with your input data
$newdata = array(
'username' => $user_name,
'email' => $email,
'logged_in' => TRUE
);
$this->session->set_userdata($newdata);
Codeigniter Session Library

Creating Cookies in Codeigniter

Well I have created sessions but having trouble implementing cookies in my website. In config file i have set $config['sess_expire_on_close'] = TRUE; so that user's session expires on closing browser.
Now what i want is, On login if user checks remember me ... all data should be stored in a cookie so that on closing browser, user is still logged on.
function login($email, $password, $loginas) {
if ($loginas == 'user') {
$this->db->select('*');
$this->db->where('email', $email);
$this->db->where('password', $password);
$query = $this->db->get("user_info");
if ($query->num_rows() > 0) {
foreach ($query->result() as $rows) {
$newdata = array('id' => $rows->id,
'firstname' => $rows->firstname,
'lastname' => $rows->lastname,
'address' => $rows->address,
'city' => $rows->city,
'email' => $rows->email,
'phone' => $rows->phone,
'logged_in' => TRUE,
);
}
$this->session->set_userdata($newdata);
if ($rememberme == 'on') {
// create a cookie here with all data that i have put in session
}
return TRUE;
}
return FALSE;
}
}
Does creating cookie automatically creates session? or we have put these data in session manually again?
In CodeIgniter, you can use set_cookie()
$cookie = array(
'name' => 'The Cookie Name',
'value' => 'The Value',
'expire' => '86500',
'domain' => '.example.com',
'path' => '/',
'prefix' => 'myprefix_',
'secure' => TRUE
);
$this->input->set_cookie($cookie);
First of all you need to load cookie helper
$this->load->helper('cookie');
Set your cookie
$cookie = array(
'name' => "cookieName",
'value' => array('id'=>$rows->id,
'firstname'=>$rows->firstname,
'lastname'=>$rows->lastname,
'address'=>$rows->address,
'city'=>$rows->city,
'email'=>$rows->email,
'phone'=>$rows->phone,
'logged_in'=>TRUE
) ,
'expire' => '86500',
);
Just pass your array into set cookie
$this->input->set_cookie($cookie);
And you can retrieve it using
$cookie['cookieName']['id'];
Also read manual

Moving uploaded files to the logined user folder

Hello so here is the problem i have a login/register system and when the user creates his account a new folder gets created with same name as he puts username so if the username is test123 a folder test123 gets created. Now the problem is i dont know how to move files that user uploads with the upload system to his directory. And ofc user has to be loged in after he register to even upload files.
here is upload.php
<?php
if($_POST[submit]) {
$name = $_FILES['upload']['name'];
$temp = $_FILES['upload']['tmp_name'];
$type = $_FILES['upload']['type'];
$size = $_FILES['upload']['size'];
if($size <= 5000000){
move_uploaded_file($temp,"userfiles/$name");
echo "File: $name was uploaded!";
} else{
echo "Wrong size!";
}
} else {
header("Location: mojprofil.php");
}
?>
so actualy at the move_uploaded_file($temp, "userfiles/$name"); in the folder userfiles there is a folder for each user that registers
and here is the register.php:
<?php
require_once 'core/init.php';
if(input::exists()) {
if(Token::check(Input::get('token'))) {
$validate = new Validate();
$validation = $validate->check($_POST, array(
'username' => array(
'required' => true,
'min' => 2,
'max' => 20,
'unique' => 'users'
),
'password' => array(
'required' => true,
'min' => 6
),
'password_again' => array(
'required' => true,
'matches' => 'password'
),
'name' => array(
'required' => true,
'min' => 2,
'max' => 50
)
));
if($validation->passed()) {
$user = new User();
$salt = Hash::salt(32);
try {
$user_dir = Input::get('username');
$user->create(array(
'username' => Input::get('username'),
'password' => Hash::make(Input::get('password'), $salt),
'salt' => $salt,
'name' => Input::get('name'),
'joined' => date('Y-m-d H:i:s'),
'group' => 1
));
Session::flash('home', '<h3>Registracija uspešna!</h3>');
mkdir(__DIR__.'/userfiles/'.$user_dir);
Redirect::to('mojprofil.php');
} catch (Exception $e) {
die($e->getMessage());
}
} else {
foreach($validation->errors() as $error) {
echo $error, '<br>';
}
}
}
}
?>
In my experience, I've always used a full server path when setting an upload path to any given directory.
So instead of this:
move_uploaded_file($temp,"userfiles/$name");
Try this:
... $tmp_filename= $_FILES['yourFile]['tmp_name']
move_uploaded_file($tmp_filename,'/your/full/server/path/userfiles/'.$name);
Also, if your user has to be logged in, I'm assuming you might track their user id or something unique in some sort of session variable.
If you are setting the directory name based off of a _FILES variable, I think you might run risk of getting folder names that don't match user id/ username.
It would be better, in my opinion, to grab the username from some sort of query first to ensure everything matches. For example:
$username = get_user($_SESSION['user_id'); // returns user data -> id, username etc...
move_uploaded_file($tmp_filename,'/your/full/server/path/userfiles/'.$username);
That would give you something like:
/public_html/foo/bar/userfiles/username/
This is very, very rough but something along these lines:
$user_data = array();
$user_data['username'] = $_POST['username'];
...
...
// Logic to clean data before insert into DB.
$user = create_user($user_data); // Return username, id or something unique.
if ($user) { // This contains username or false
// Create directory with returned username then upload file
...
...
// Logic to prep the file for upload
move_uploaded_file($tmp_filename,'/your/full/server/path/userfiles/'.$user);
}

Categories