一个非常简单的http基本auth实现。
basicauth的Python项目详细描述
#python basic auth
一个死板的简单http基本身份验证编码器和解码器。为什么?因为http应该是
非常容易删除的。这就是原因。
![http基本身份验证?(https://github.com/rdegges/python-basic auth/raw/master/http://u-basic-auth.jpg)
>要安装“python-basicauth”,只需运行“pip install basicauth``即可安装“python-basicauth````并
>要生成编码的基本身份验证字符串,请生成编码的基本身份验证字符串:
``Python
>;>;gt;从Basicauth导入编码
>;gt;用户名,密码='rdeges','omghax!!!
>;>encoded_str=encode(用户名、密码)
>;>print encoded_str
'basic cmrlz2dlczpvbwdoyxglmjelmje='
```
>解码编码的基本身份验证字符串:
``python
>;
>;编码的“str=”基本的cmrlz2dlczpvbwdoyxglmjelmje='”来自上面的示例。
>;>username,password=decode(编码的)“str”
>;>print(用户名,密码)
('rdeges','omghax!!!')
```
>我们还可以直接对哈希进行解码:
````python
>>>gt;从Basicauth导入解码
>>;>gt;
>>gt;从上例中,编码的“cmrlz2dlcz2dlczpvdwidyzglzglzglmjelmjelmje='='''''''''''''cmrlz2dlcz2dlczpvzzldzzzldzglmjelmjelmje=''''''''''''''''''''''''''''''''''''''''''''''''''该死!!!')
````
,如果有错误:
```python
>>>gt;从Basicauth导入解码,解码错误
>>;编码的“lol-omg cmrlz2dlczpvbwdwwzglzglzglmjelmjelmje='无效的哈希值。
>;用户名、密码=解码(编码的“解码的”str)
回溯(最近一次调用的最后一次):
>file”<;stdin>;gt;从Basicauth导入解码,解码的“解码错误”解码的“解码的错误
>;编码的”编码的“lol-str='lol-lol-om“,第1行,输入<;module>;
文件“basicauth/uu init_uuu.py”,第49行,在decode
raise decode error
basicauth.decode error
````
**注意**:[http基本身份验证规范](http://www.ietf.org/rfc/rfc2617.txt)
不允许**在用户名
字段中包含任何冒号字符(`:`)。密码字段中允许冒号,但仅此而已。
[构建状态](https://secure.travis-ci.org/rdeges/python-basicauth.png?branch=master)(http://travis ci.org/rdeges/python basicauth)
要运行测试吗?没问题:
``` bash
$git clone git://github.com/rdeges/python basicauth.git
$cd python basicauth
$python setup.py develop
…
$pip install-r requirements.txt;安装测试依赖项。
$noests
………
在0.166s内
ok
````
一个死板的简单http基本身份验证编码器和解码器。为什么?因为http应该是
非常容易删除的。这就是原因。
![http基本身份验证?(https://github.com/rdegges/python-basic auth/raw/master/http://u-basic-auth.jpg)
>要安装“python-basicauth”,只需运行“pip install basicauth``即可安装“python-basicauth````并
>要生成编码的基本身份验证字符串,请生成编码的基本身份验证字符串:
``Python
>;>;gt;从Basicauth导入编码
>;gt;用户名,密码='rdeges','omghax!!!
>;>encoded_str=encode(用户名、密码)
>;>print encoded_str
'basic cmrlz2dlczpvbwdoyxglmjelmje='
```
>解码编码的基本身份验证字符串:
``python
>;
>;编码的“str=”基本的cmrlz2dlczpvbwdoyxglmjelmje='”来自上面的示例。
>;>username,password=decode(编码的)“str”
>;>print(用户名,密码)
('rdeges','omghax!!!')
```
>我们还可以直接对哈希进行解码:
````python
>>>gt;从Basicauth导入解码
>>;>gt;
>>gt;从上例中,编码的“cmrlz2dlcz2dlczpvdwidyzglzglzglmjelmjelmje='='''''''''''''cmrlz2dlcz2dlczpvzzldzzzldzglmjelmjelmje=''''''''''''''''''''''''''''''''''''''''''''''''''该死!!!')
````
,如果有错误:
```python
>>>gt;从Basicauth导入解码,解码错误
>>;编码的“lol-omg cmrlz2dlczpvbwdwwzglzglzglmjelmjelmje='无效的哈希值。
>;用户名、密码=解码(编码的“解码的”str)
回溯(最近一次调用的最后一次):
>file”<;stdin>;gt;从Basicauth导入解码,解码的“解码错误”解码的“解码的错误
>;编码的”编码的“lol-str='lol-lol-om“,第1行,输入<;module>;
文件“basicauth/uu init_uuu.py”,第49行,在decode
raise decode error
basicauth.decode error
````
**注意**:[http基本身份验证规范](http://www.ietf.org/rfc/rfc2617.txt)
不允许**在用户名
字段中包含任何冒号字符(`:`)。密码字段中允许冒号,但仅此而已。
[构建状态](https://secure.travis-ci.org/rdeges/python-basicauth.png?branch=master)(http://travis ci.org/rdeges/python basicauth)
要运行测试吗?没问题:
``` bash
$git clone git://github.com/rdeges/python basicauth.git
$cd python basicauth
$python setup.py develop
…
$pip install-r requirements.txt;安装测试依赖项。
$noests
………
在0.166s内
ok
````