{"id":3043,"date":"2012-06-04T18:27:32","date_gmt":"2012-06-04T16:27:32","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=3043"},"modified":"2015-10-28T18:19:13","modified_gmt":"2015-10-28T16:19:13","slug":"detect-gmail-2-step-authentication","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/detect-gmail-2-step-authentication","title":{"rendered":"Detect Gmail&#8217;s 2-Step Authentication"},"content":{"rendered":"<p>Gmail urges users to use 2-step authentication. Basically this means that Gmail texts users special codes that need to be entered every time they logs-in to theirs account.<\/p>\n<p>This article describes how you can detect 2-step authentication is turned on. This way you can instruct the user to either disable it or to <a href=\"http:\/\/support.google.com\/accounts\/bin\/answer.py?hl=en&#038;answer=185833\">generate and use application specific password<\/a> for your program.<\/p>\n<p>When 2-steps verification is turned on, Imap.Login method will throw an ServerException with following message:<\/p>\n<p>&#8220;[ALERT] Application-specific password required: http:\/\/support.google.com\/accounts\/bin\/answer.py?answer=185833 (Failure)&#8221;<\/p>\n<p>You can use it to check if application-specific password is needed:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\ntry\r\n{\r\n   imap.UseBestLogin(&quot;pat&quot;, &quot;password&quot;);\r\n}\r\ncatch (ServerException ex)\r\n{\r\n   bool needs2StepVerification = ex.Message.Contains(&quot;Application-specific password required&quot;);\r\n   imap.Close();\r\n   if (needs2StepVerification)\r\n       Console.WriteLine(&quot;Application-specific password required&quot;);\r\n   retrun;\r\n}\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nTry\r\n\timap.UseBestLogin(&quot;pat&quot;, &quot;password&quot;)\r\nCatch ex As ServerException\r\n\tDim needs2StepVerification As Boolean = ex.Message.Contains(&quot;Application-specific password required&quot;)\r\n\timap.Close()\r\n\tIf needs2StepVerification Then\r\n\t\tConsole.WriteLine(&quot;Application-specific password required&quot;)\r\n\tEnd If\r\n\tretrun\r\nEnd Try\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Gmail urges users to use 2-step authentication. Basically this means that Gmail texts users special codes that need to be entered every time they logs-in to theirs account. This article describes how you can detect 2-step authentication is turned on. This way you can instruct the user to either disable it or to generate and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15,25,28,77,57],"class_list":["post-3043","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-gmail","tag-imap","tag-imap-component","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3043"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=3043"}],"version-history":[{"count":9,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3043\/revisions"}],"predecessor-version":[{"id":4980,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3043\/revisions\/4980"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=3043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=3043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=3043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}