Change admin password in drupal 7 - drupal

I am using built in Drupal 7 user module, fore user registration, forgot-your-password-emails and all that stuff.
I have forgotten my admin password. I have access to my website which is hosted on 1and1.com and also have access to mysql?
Is it possible to change password or email address through SQL so that I can access the admin page?
If it possible how? Can you somebody help me with this?
Thanks!

If you have Drush installed, you just have to enter the following command in the terminal from anywhere inside the site root.
drush upwd admin --password=mynewpassword
Here, admin is the user name; who's password will be changed to mynewpassword.

After several research I tried the following code stored it as a php file in the root directory
saved it as password-reset-admin.php
<?php
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once DRUPAL_ROOT . '/includes/password.inc';
if (isset($_GET['pass']) && !empty($_GET['pass'])) {
$newhash = user_hash_password($_GET['pass']);
}
else {
die('Retry with ?pass=PASSWORD set in the URL');
}
$updatepass = db_update('users')
->fields(array(
'pass' => $newhash,
// 'name' => 'admin',
// 'mail' => 'yourmail#domain.com';
))
->condition('uid', '1', '=')
->execute();
print "Done. Please delete this file immediately!";
drupal_exit();
?>
And after that access the php file through the following:
https://yoursite.com/password-reset-admin.php?pass=newpassword
It just worked..:) Hope it helps others.
Please make sure you delete the file.

To change the password, you need to have shell access to your website. If not, download a copy of drupal 7 on your local machine.
Then, open your terminal and navigate to your Drupal 7 root folder. Then type the following command:
./scripts/password-hash.sh NEW_PASSWORD
Replace NEW_PASSWORD with the new password you need.
This will output a new password hash, copy this password and go to your database manager (phpMyAdmin or similar) and change the admin password to newly generated text.
I don't know of other way to do that, because Drupal is not using MD5 anymore and use a hashing algorithm instead.

Change directory to your Drupal's root.
Then generate the new hash.
In case of Drupal 7:
$ php scripts/password-hash.sh 'your-new-pass-here'
Then execute SQL query to update the administrator's password:
UPDATE users_field_data SET pass='$S$Do7UQjqtEELNccdi92eCXcVJ2KnwUeHrSbK3YhFm8oR3lRJQbMB2' WHERE uid = 1;
In case of Drupal 8 path to script will be:
$ php core/scripts/password-hash.sh 'your-new-pass-here'
Update DB:
UPDATE users_field_data SET pass='$S$Do7UQjqtEELNccdi92eCXcVJ2KnwUeHrSbK3YhFm8oR3lRJQbMB2' WHERE uid = 1;
Clean the cache:
DELETE FROM cache_entity WHERE cid = 'values:user:1';

If you have access to database, then...
Go to the users table in your database and change the admin's email to an email that you have access to.
Afterward, head over to yoursite.com/user/password and enter the email that just changed.
Go to your email and click on the reset link to go into your site and reset your password.
Done!

Tested and it works!
With the access to the table "users" in your Database via PhpMyAdmin for example (i.e. this table can have a prefix that you have already mentionned during the Drupal installation part, so yourPrefix_ can be your project's name as mywebsitename_, and in this case you'll have mywebsitename_users).
You should alter the "pass" column associated with the "uid" column with the value 1 (i.e 1 for the admin user account).
As the encrypted value for the password: Admin_12345 is =>
$S$DifCVXg9tNtHadziyyQJQVLAaZzW5EgS6OjR56D.mk8MpNQs1II2
You can accede to your admin account after replacing the old hashed password value stored in your database that you have totally forgotten.
Don't forget to change the password: Admin_12345 after you accede to your account with an other one.

You can generate query here and run the query in database.

Related

How to create encrypted hash passwords for drupal 7

After searching over internet I came to know that With drupal 7, password are no more encrypted through md5.
What are possible ways to get passwords encrypted in Drupal 7??
With drupal 7, password are no more encrypted through md5.
There are several way to get/set a password in drupal7.
Using drush (for your information, not used in your case):
drush upwd admin --password="newpassword"
Without drush, if you have a cli access to the server : (for your information, not used in your case)
cd <drupal root directory>
php scripts/password-hash.sh 'myPassword'
Now copy the resultant hash and paste it into the query:
update users set name='admin', pass='pasted_big_hash_from_above' where uid=1;
Thanks Malik.
After search I found different solutions. Following solution also works
If you are working on a remote environment on which you cannot connect, you can put this specified code in a file such as password.php such as this one:
<?php
if (isset($_GET['p'])) {
require_once dirname(__FILE__) . '/includes/bootstrap.inc';
require_once dirname(__FILE__) . '/includes/password.inc';
print _password_crypt('sha512', $_GET['p'], _password_generate_salt(DRUPAL_HASH_COUNT));
exit();
}
print "No password to hash.";
And then hit your site using: http://domain.tld/password.php?p='MyPassword'. The hash will appear on your browser's tab.
Don't forget to remove it once you done it.
So, if you want to use some password function generation, have a look on _password_crypt() and _password_generate_salt()
The user_hash_password() function can be used to hash password, if you want to use it outside from outside Drupal, you need to bootstrap Drupal configuration.
chdir("/path/to/drupal");
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
user_hash_password($password);

Wordpress admin

Need to reset my admin details on wordpress, I have no idea what my admin username or password is; furthermore I don't have access to phpmyadmin either as I wasn't the one to set it up. would love some feedback!
You can log in if you have access to the FTP where the site is hosted. If you have access, create a new php-file in the root directory (autologin.php for example), paste the following code and then visit your new file through the browser (link.com/autologin.php for example).
<?php
require_once('wp-load.php');
auto_login("admin"); //Change this to your username.
function auto_login($username) {
$user = get_userdatabylogin($username);
$user_id = $user->ID;
wp_set_current_user($user_id, $user_login);
wp_set_auth_cookie($user_id);
do_action('wp_login', $user_login);
wp_redirect(admin_url());
}
?>
Do you have access to the wordpress ftp?
If yes, you need to download the WP config file and now you have access to DB
You can goto phpMyAdmin
Under tables goto wp_users
Then for whichever user you want to edit details click edit
replace password and change category to MD5

Wordpress database connection

I'm creating a wordpress business to let user register into your website. I know that wp-config.php file is used to connect to the db. But in my themes folder do I need to connect to the database again as in the code below.
connect.php
mysql_connect('localhost','xxxxx','xxxxxx');
mysql_select_db('xxxxxx');
init.php
require 'connect.php';
registration.php
include 'init.php';
I have used $connect_error = "Database error!"; in my connect.php file and key in a a wrong host and username, but it doesn't prompt me with error message. I think it doesn't connected to my database.
It is possible to connect to wordpress database from your own theme
so that whenever user will visit site they can see form which can be validate
Process is as follows :
1.To let user register into website there is need to create form on frontend
2.Create your own theme http://www.siteground.com/tutorials/wordpress/wordpress_create_theme.htm
3.Add Subscribe table to your user database with columns as name, username, password, email_id
4.In index.php file add following code to that file to connect database
$myrows = $wpdb->get_results( "INSERT INTO Subscribe(name, username, password, email_id)VALUES('$name', '$uname', '$pswd', '$email')" );
The $wpdb object is not limited to the default tables created by WordPress.
It can be used to read data from any table in the WordPress database such as custom plugin table

How to change WebDAV password locally

I can't figure out how to change the webdav password. I've done some searching, found many resources of how to add a new user to webdav, but nothing about changing password. Anyone know?
Passwords are stored in webdav.htpasswd file.
If you open it, you will see an entry like this
wampp:XAMPP with WebDAV:bc7f2b670e7e965e307feb30492e642e
That's the entry for user wampp: in realm XAMPP with WebDAV: with password which is encrypted.
To change password, you should use htdigest.exe.
See manual. It is used to create and update user authentication files. You should find in the bin directory of xampp installation.
To do that, do :
htdigest.exe "pathto/webdav.htpasswd" "XAMPP with WebDAV" yourusername
This will be returned:
Adding user yourusername in realm "XAMPP with WebDAV"
You will then be asked for the password for yourusername
New password: yourpassword
Re-type new password: yourpassword
Reference: http://www.apachefriends.org/f/viewtopic.php?f=16&t=38897
Replace the content of the file C:\Program Files\xampp\security\htpasswd.webdav with your username, a colon and the password. Note: Everyone who can see this file can see the password!
Assuming you're talking about doing a password change at the server from a client, I don't believe WebDAV supports such a transaction.
You'd use something like a shell logon or a Web-based admin page to do this.
This always struck me as odd for a lot of network services, for example FTP or email. It seems to be common though.

password recovery for drupal

i forgot my drupal user id and password. Is there any way to recover it
http://example.com/<path-to-drupal>/user/password should bring you to a page where you can request a reset/new-password.
Edit:
The above path applies if you have 'clean URLs' enabled, if not use http://example.com/<path-to-drupal>/?q=user/password
This solution is valid for Drupal 5 or 6 but not for Drupal 7. This version does not use a standard hashed password. You can get your encoded password running the following command:
php /path_to_drupal_files/scripts/password-hash.sh your_password
Then you can see your password hash. This is the string that you should use in the database to update the admin password. You can use the following SQL query to update the Drupal database.
UPDATE users SET pass='YOUR_PASSWORD_HASH' where uid=1;
If you don't have access to the email (or want to bulk-update the passwords) you can update the database with a query like:
UPDATE users SET pass = md5('NEWPASSWORD') WHERE name = 'admin'

Resources