{"id":1044,"date":"2015-10-05T07:53:55","date_gmt":"2015-10-05T07:53:55","guid":{"rendered":"http:\/\/invisiblezero.net\/?p=1044"},"modified":"2024-07-22T09:23:38","modified_gmt":"2024-07-22T09:23:38","slug":"laravel-change-user-password-with-tinker-tool","status":"publish","type":"post","link":"http:\/\/ndthanh.com\/laravel-change-user-password-with-tinker-tool\/","title":{"rendered":"Laravel – Change user password with tinker tool"},"content":{"rendered":"\n

Today just asked myself if i can change user password in Laravel via command line, so things will be easier for us to work with Laravel products. I bet many of you use default Laravel user model (which is good for us in this case). if you do, this article is for you, i found an interesting tool within Laravel command line interface name \u2018tinker\u2019<\/p>\n\n\n\n\n\n\n\n

if you use Ruby on Rails, you can think of Laravel tinker tool as something like `rails console` command , it allows you to interact with your application, you can access directly to models, helpers, classes …etc\u2026 Have you started liking it yet ? \ud83d\ude09<\/p>\n\n\n\n

ok, it\u2019s time to get to main purpose of this article – to change user password with tinker tool – a brief introduction to tinker tool . i will make it step-by-step<\/p>\n\n\n\n

Step 1 – start laravel tinker tool<\/p>\n\n\n\n

cd <your_larave_project_directory_path>\nphp artisan tinker\nPsy Shell v0.4.4 (PHP 5.5.28 \u2014 cli) by Justin Hileman\n>>><\/code><\/code><\/pre>\n\n\n\n

now you can start typing whatever you like behind >>> prommpt.<\/p>\n\n\n\n

Step 2 – Access to User Model<\/p>\n\n\n\n

>>> $user = App\\User::where('email', 'nd.thanh@outlook.com')->first();\n=> <App\\User #0000000051a8ab8a000000014bcb4fe8> {\nid: 342,\nname: 'Thanh, nguyen',\nemail: 'nd.thanh@outlook.com',\ncreated_at: '2015-09-21 19:28:14',\nupdated_at: '2015-09-23 07:48:14',\ncompany: null,\napi_key: null,\ncb_user_id: '',\nfirstname: null,\nlastname: null,\ntimezone: null,\nlast_activity: null,\nenabled: null,\navatar: '',\nidentifier: '',\nadmin_hash: 'admin:9569a4dc201b26a01f19dd7594843da1',\ngroup_id: 0,\nrole_id: 0\n}<\/code><\/pre>\n\n\n\n

so this is the query `App\\User::where(’email’, ‘nd.thanh@outlook.com’)->first();` , we have an user instance for my user account now. let\u2019s update password for this user account<\/p>\n\n\n\n

Step 3 – update password
Laravel uses Bcrypt to make password hash by default, which means you can generate a password like string with this command<\/p>\n\n\n\n

>>> echo Hash::make('yourpassword');\n$2y$10$AR.gZdnx6rc9NLLtnuoPzOpOy3D\/NZ.GqhFAl0lO0EgJ8boyqX8yK\n=> null<\/code><\/pre>\n\n\n\n

ok, we know how to make password , time to update user instance<\/p>\n\n\n\n

>>> $user->password = Hash::make('abc123');\n=> '$2y$10$At6GpoCsB.BQOacms87fAubGRMtu2UqJ44f53IN2EdT43IGDI.5oO'\n\n>>> $user->save()\n=> true<\/code><\/pre>\n\n\n\n

that\u2019s it. my new password is now \u2018abc123\u2019 , you can change yours to what ever you like.<\/p>\n","protected":false},"excerpt":{"rendered":"

Today just asked myself if i can change user password in Laravel via command line, so things will be easier for us to work with Laravel products. I bet many of you use default Laravel user model (which is good for us in this case). if you do, this article is for you, i found…<\/p>\n

Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":1475,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[97],"tags":[98,61,62,51,55],"aioseo_notices":[],"views":29,"_links":{"self":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts\/1044"}],"collection":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/comments?post=1044"}],"version-history":[{"count":19,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts\/1044\/revisions"}],"predecessor-version":[{"id":1455,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts\/1044\/revisions\/1455"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/media\/1475"}],"wp:attachment":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/media?parent=1044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/categories?post=1044"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/tags?post=1044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}