{"id":14195,"date":"2020-06-03T05:20:37","date_gmt":"2020-06-03T05:20:37","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=14195"},"modified":"2021-11-05T11:01:34","modified_gmt":"2021-11-05T11:01:34","slug":"how-to-setup-laravel-default-password-reset-mail","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-setup-laravel-default-password-reset-mail\/","title":{"rendered":"How to Setup Laravel default password reset mail"},"content":{"rendered":"\n<p>Most web applications provide a way for users to reset their forgotten passwords. Rather than forcing you to re-implement this on each application, Laravel provides convenient methods for sending password reminders and performing password resets.<\/p>\n\n\n\n<p>Laravel includes&nbsp;<code>Auth\\ForgotPasswordController<\/code>&nbsp;and&nbsp;<code>Auth\\ResetPasswordController<\/code>&nbsp;classes that contains the logic necessary to e-mail password reset links and reset user passwords. All of the routes needed to perform password resets may be generated using the&nbsp;<code>php artisan make:auth<\/code>&nbsp;Composer package:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"229\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/06\/Capture.png\" alt=\"\" class=\"wp-image-14196\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/06\/Capture.png 800w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/06\/Capture-300x86.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/06\/Capture-768x220.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p>Once you have defined the routes and views to reset your user&#8217;s passwords, you may access the route in your browser at&nbsp;<code>\/password\/reset<\/code>. The&nbsp;<code>ForgotPasswordController<\/code>&nbsp;included with the framework already includes the logic to send the password reset link e-mails, while the&nbsp;<code>ResetPasswordController<\/code>&nbsp;includes the logic to reset user passwords.<\/p>\n\n\n\n<p>After a password is reset, the user will automatically be logged into the application and redirected to&nbsp;<code>\/home<\/code>. You can customize the post password reset redirect location by defining a&nbsp;<code>redirectTo<\/code>&nbsp;property on the&nbsp;<code>ResetPasswordController<\/code>:<\/p>\n\n\n\n<p>You just need to make some changes on <strong>.env <\/strong>, you can find these lines in your env file We are using Gmail SMTP Server to send Email in Laravel for this.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>1:-<\/strong> <strong>Creating \/ Using an existing Gmail account to create app passwords.<\/strong><\/p>\n\n\n\n<p>I&#8217;m using my existing Gmail account, butt in case if you wish to create a new account you can go for  that also, Clink on this <a href=\"https:\/\/accounts.google.com\/signup\/v2\/webcreateaccount?hl=en&amp;flowName=GlifWebSignIn&amp;flowEntry=SignUp\" target=\"_blank\" rel=\"noreferrer noopener\">LINK <\/a>to create one <\/p>\n\n\n\n<p class=\"has-normal-font-size\"> <strong>Next we need to enable 2 step Verification in Gmail as follows:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Login into Gmail .<\/li><li>To be able to create app passwords we need to first enable 2 Step Verification .<\/li><li>Click on the user icon and select&nbsp;<strong>\u201cGoogle Account\u201d<\/strong>&nbsp;.<\/li><li>Next we need to select&nbsp;<strong>Security<\/strong>&nbsp;from the left nav , then select&nbsp;<strong>\u201c2 Step Verification\u201d<\/strong>&nbsp;. (Doing this would ask you to login again and then Gmail would authenticate you further using OTP )<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"318\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/06\/1_iBaDmPbw5SWMxOPWLvETTQ.png\" alt=\"\" class=\"wp-image-14198\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/06\/1_iBaDmPbw5SWMxOPWLvETTQ.png 800w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/06\/1_iBaDmPbw5SWMxOPWLvETTQ-300x119.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/06\/1_iBaDmPbw5SWMxOPWLvETTQ-768x305.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Now we generate the app password that we would be using in the Laravel Application , again clicking on the&nbsp;<strong>Google Account<\/strong>&nbsp;in the user icon&nbsp;<strong>-&gt;Security -&gt;App Passwords<\/strong>&nbsp;. (This would again ask you to login and then authenticate using OTP)<\/li><li>We need to select \u201cMail\u201d as the app and \u201cOther (Custom name)\u201d as the device from the drop downs .<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"767\" height=\"442\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/06\/1_-QrZMxDLyYVNTCmx60REcw.png\" alt=\"\" data-id=\"14199\" data-full-url=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/06\/1_-QrZMxDLyYVNTCmx60REcw.png\" data-link=\"https:\/\/www.devopsschool.com\/blog\/?attachment_id=14199\" class=\"wp-image-14199\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/06\/1_-QrZMxDLyYVNTCmx60REcw.png 767w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/06\/1_-QrZMxDLyYVNTCmx60REcw-300x173.png 300w\" sizes=\"auto, (max-width: 767px) 100vw, 767px\" \/><\/figure><\/li><\/ul><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Selecting this would ask you to add the name of the Application for which you wish to generate the password and once added click&nbsp;<strong>GENERATE<\/strong>.<\/li><li>This would open a pop up with your&nbsp;<strong>16 character app password<\/strong>&nbsp;. (Kindly copy this and keep it safe).<\/li><li>We are all set to add these detail\u2019s to the Application.<\/li><\/ul>\n\n\n\n<p class=\"has-normal-font-size\"><strong>2. Adding Gmail Account detail\u2019s to the Laravel Application:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>We need to edit the following in the&nbsp;<strong><em>.env<\/em><\/strong>&nbsp;file<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>MAIL_DRIVER=smtp<br>MAIL_HOST=mailtrap.io<br>MAIL_PORT=2525<br>MAIL_USERNAME=null<br>MAIL_PASSWORD=null<br>MAIL_ENCRYPTION=null<\/p><\/blockquote>\n\n\n\n<p><strong><em>with<\/em><\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>MAIL_DRIVER=smtp<br>MAIL_HOST=smtp.gmail.com<br>MAIL_PORT=465<br><a href=\"mailto:MAIL_USERNAME=youraccount@gmail.com\" target=\"_blank\" rel=\"noreferrer noopener\">MAIL_USERNAME=youraccount@gmail.com<\/a><br>MAIL_PASSWORD=yourapppassword<br>MAIL_ENCRYPTION=ssl<\/p><\/blockquote>\n\n\n\n<ul class=\"wp-block-list\"><li>There is no need for us to make any change in the&nbsp;<strong>config\/mail.php<\/strong>&nbsp;file , since it would pick the values from the&nbsp;<strong>.env<\/strong>&nbsp;file.<\/li><li><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"356\" height=\"200\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/06\/200.gif\" alt=\"\" data-id=\"14200\" data-full-url=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/06\/200.gif\" data-link=\"https:\/\/www.devopsschool.com\/blog\/?attachment_id=14200\" class=\"wp-image-14200\"\/><\/figure><\/li><\/ul><\/figure>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_23970\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_50002\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_23970\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Most web applications provide a way for users to reset their forgotten passwords. Rather than forcing you to re-implement this on each application, Laravel provides convenient methods&#8230; <\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5201],"tags":[5203,6109,6108],"class_list":["post-14195","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-laravel","tag-mail-server","tag-password-reset"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/14195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=14195"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/14195\/revisions"}],"predecessor-version":[{"id":24807,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/14195\/revisions\/24807"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=14195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=14195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=14195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}