Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F7159546
tweaks.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
tweaks.py
View Options
import
md5
from
twisted.cred
import
credentials
,
error
from
twisted.web2.auth.digest
import
IUsernameDigestHash
from
zope.interface
import
implements
,
Interface
def
makeHash
(
username
,
realm
,
password
):
s
=
'
%s
:
%s
:
%s
'
%
(
username
,
realm
,
password
)
return
md5
.
new
(
s
)
.
hexdigest
()
class
BasicCredentials
(
credentials
.
UsernamePassword
):
"""Custom Basic Credentials, which support both plain and hashed checks."""
implements
(
credentials
.
IUsernamePassword
,
IUsernameDigestHash
)
def
__init__
(
self
,
username
,
password
,
realm
):
self
.
username
=
username
self
.
password
=
password
self
.
realm
=
realm
def
checkHash
(
self
,
digestHash
):
return
digestHash
==
makeHash
(
self
.
username
,
self
.
realm
,
self
.
password
)
def
decode
(
self
,
response
,
request
):
try
:
creds
=
(
response
+
'==='
)
.
decode
(
'base64'
)
except
Exception
:
raise
error
.
LoginFailed
(
'Invalid credentials'
)
creds
=
creds
.
split
(
':'
,
1
)
if
len
(
creds
)
==
2
:
creds
=
BasicCredentials
(
creds
[
0
],
creds
[
1
],
self
.
realm
)
# our change
return
creds
else
:
raise
error
.
LoginFailed
(
'Invalid credentials'
)
## Now we tweak what we need
import
new
from
twisted.web2.auth.basic
import
BasicCredentialFactory
method
=
new
.
instancemethod
(
decode
,
None
,
BasicCredentialFactory
)
BasicCredentialFactory
.
decode
=
method
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Sat, Nov 23, 6:56 AM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3408968
Default Alt Text
tweaks.py (1 KB)
Attached To
Mode
rOPENXCAP OpenXCAP
Attached
Detach File
Event Timeline
Log In to Comment