Summary

I wanted to log in to my email account in a script, but thanks to two-factor authentication, the login attempts failed. I then used an app-specific password, and it worked just fine. Here’s how to generate such a password for Gmail and Microsoft.

What Is an App-Specific Password?

An app-specific password, as the name implies, is a password you create for your online accounts to be used with a specific app. For example, if you use an app that only supports passwords and no other forms of authentication, and you’ve enabledtwo-factor authenticationfor your account, you’ll have to generate and use an app-specific password in your app to log in to your account.

As you can see, when you use an app-specific password, you bypass the two-factor authentication process. Your username and the app-specific password you generate are enough to log in to your account.

“Security” and “2-Step Verification” highlighted on Google My Account.

This sometimes poses a security risk, as if someone discovers your app-specific password, they can log in to your account. In this case, you have the option to remove all or specific app-specific passwords from your accounts.

How to Generate an App-Specific Password on Google

I wrote a script to send emails using Gmail’s SMTP, but since the script didn’t support other forms of authentication, I created an app-specific password for my Google account to use in the script. Here’s how you can create one for your account.

Launch theGoogle My Account siteand sign in to your Google account. For this login, you’ll have to use your password as well as two-factor authentication. After logging in, from the site’s left sidebar, select “Security.” On the right pane, in the How You Sign In to Google section, click “2-Step Verification.”

The right-arrow icon highlighted next to “App Passwords."

If prompted, enter your account password to continue.

On the 2-Step Verification screen, at the bottom, click the right-arrow icon next to App Passwords.

On the App Passwords page, click the “App Name” field and type the name of the app you want to create a password for. This name is only for your reference; you can type any name you want. Then, click “Create.”

“App Name” and “Create” highlighted on the “App Passwords” page.

A Generated App Password window will open. You’ll see the app-specific password that Google has generated for you. Copy the password and paste it directly into your app or temporarily save it somewhere safe. Then, close the window by clicking “Done.”

You’re back on the App Passwords page, and you’ll see the entry for your newly created app password. In the future, if you’d like to remove this password, you can click the trash icon next to the password.

“Done” highlighted on the “Generated App Password” window.

Note that any apps using this passwordwon’t be able to log in to your Google accountanymore.

How to Generate an App-Specific Password on Microsoft

I sometimes also use Microsoft Outlook to send out emails from my script, and creating an app-specific password with Microsoft is also easy. To start, launch theMicrosoft Account siteand sign in to your account. You’ll have to use two-factor authentication.

From the left sidebar, select “Security” (the shield icon). On the right pane, click “Manage How I Sign In.”

The trash can icon highlighted next to an app password.

On the open page, scroll down to the App Passwords section. Here, click “Create a New App Password.”

On the following page, you’ll see an app-specific password that Microsoft has generated for you. Copy the password and save it somewhere safe, or immediately use the password in your script or app. Then, click the “Done” button.

“Security” and “Manage How I Sign In” highlighted on Microsoft Account.

Unlike Google, Microsoft doesn’t allow you to remove app-specific passwords individually. It erases all your app-specific passwords at once. If you’d like to do that, click “Remove Existing App Passwords.” In the prompt that opens, choose “Remove.”

If you’d like to use certain apps with your Microsoft account in the future, you’ll have to re-generate app-specific passwords for all those apps in your Microsoft account. This is quite cumbersome, but this is the only option you currently have with Microsoft.

“Create a New App Password” highlighted on the “Security” page.

And that’s how I generate and use app-specific passwords for my Google and Microsoft accounts. While you’re at it, consider learningsome tips to secure your online accounts.

“Done” highlighted on the “Use This App Password to Sign In” page.

“Remove” highlighted on the “Remove Existing App Passwords” window.