<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python on Huy Minh Ha</title><link>https://minhhh.github.io/tags/python/</link><description>Recent content in Python on Huy Minh Ha</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 02 Oct 2016 00:00:00 +0700</lastBuildDate><atom:link href="https://minhhh.github.io/tags/python/index.xml" rel="self" type="application/rss+xml"/><item><title>Generate one-time password from the command line</title><link>https://minhhh.github.io/posts/using-otp/</link><pubDate>Sun, 02 Oct 2016 00:00:00 +0700</pubDate><guid>https://minhhh.github.io/posts/using-otp/</guid><description>&lt;p&gt;One-time password is pretty common these days for any type of account that offers two-factor authentication. We can use an app to generate OTP but it would be troublesome if we lost the app or the phone. Fortunately there&amp;rsquo;s a simple way to generate OTP programmatically using libraries such as Python &lt;code&gt;OneTimePass&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;First, install &lt;code&gt;OneTimePass&lt;/code&gt; with &lt;code&gt;pip&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;pip install onetimepass
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Then you get the secret generated from the service provider you&amp;rsquo;re using. Normally it would be a time-based token, such as the ones you use for Google Authenticator.&lt;/p&gt;
&lt;p&gt;To get time-based token you invoke it like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;import onetimepass as otp
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;my_secret = &amp;#39;MFRGGZDFMZTWQ2LK&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;my_token = otp.get_totp(my_secret)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;print my_token
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Remember to store your secret safely.&lt;/p&gt;</description></item><item><title>A Guide to Python's Magic Methods</title><link>https://minhhh.github.io/posts/py-magic-methods/</link><pubDate>Sun, 19 Oct 2014 00:00:00 +0700</pubDate><guid>https://minhhh.github.io/posts/py-magic-methods/</guid><description>&lt;p&gt;&lt;a class="link" href="https://github.com/minhhh/magicmethods" target="_blank" rel="noopener"
 &gt;minhhh/magicmethods/README.md&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Python decorator tutorial</title><link>https://minhhh.github.io/posts/python-decorators/</link><pubDate>Sun, 05 Oct 2014 00:00:00 +0700</pubDate><guid>https://minhhh.github.io/posts/python-decorators/</guid><description>&lt;p&gt;&lt;a class="link" href="https://github.com/minhhh/wiki" target="_blank" rel="noopener"
 &gt;minhhh/wiki/py_decorators.md&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>