Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
eta
gajim
Commits
09dbf12b
Commit
09dbf12b
authored
18 years ago
by
nkour
Browse files
Options
Downloads
Patches
Plain Diff
commit Gustavo's src/common/passwords.py
parent
1a0c7811
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/common/passwords.py
+84
-0
84 additions, 0 deletions
src/common/passwords.py
with
84 additions
and
0 deletions
src/common/passwords.py
0 → 100644
+
84
−
0
View file @
09dbf12b
##
## Copyright (C) 2006 Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
## Copyright (C) 2006 Nikos Kouremenos <kourem@gmail.com>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 2 only.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
__all__
=
[
'
get_password
'
,
'
save_password
'
]
import
gobject
from
common
import
gajim
try
:
import
gnomekeyring
except
ImportError
:
USER_HAS_GNOMEKEYRING
=
False
else
:
USER_HAS_GNOMEKEYRING
=
True
class
SimplePasswordStorage
(
object
):
def
get_password
(
self
,
account_name
):
return
gajim
.
config
.
get_per
(
'
accounts
'
,
account_name
,
'
password
'
)
def
save_password
(
self
,
account_name
,
password
):
gajim
.
connections
[
account_name
].
password
=
password
class
GnomePasswordStorage
(
object
):
def
__init__
(
self
):
self
.
keyring
=
gnomekeyring
.
get_default_keyring_sync
()
def
get_password
(
self
,
account_name
):
conf
=
gajim
.
config
.
get_per
(
'
accounts
'
,
account_name
,
'
password
'
)
try
:
unused
,
auth_token
=
conf
.
split
(
"
gnomekeyring:
"
)
auth_token
=
int
(
auth_token
)
print
"
load: token for account %s: %i
"
%
(
account_name
,
auth_token
)
except
ValueError
:
password
=
conf
## migrate the password over to keyring
self
.
save_password
(
account_name
,
password
,
update
=
False
)
return
password
try
:
return
gnomekeyring
.
item_get_info_sync
(
self
.
keyring
,
auth_token
).
get_secret
()
except
gnomekeyring
.
DeniedError
:
return
None
def
save_password
(
self
,
account_name
,
password
,
update
=
True
):
display_name
=
(
"
Gajim account %s
"
%
(
account_name
,))
attributes
=
dict
(
account_name
=
str
(
account_name
),
gajim
=
1
)
auth_token
=
gnomekeyring
.
item_create_sync
(
self
.
keyring
,
gnomekeyring
.
ITEM_GENERIC_SECRET
,
display_name
,
attributes
,
password
,
update
)
print
"
save(update=%i): token for account %s: %i
"
%
(
update
,
account_name
,
auth_token
)
token
=
"
gnomekeyring:%i
"
%
(
auth_token
,)
gajim
.
config
.
set_per
(
'
accounts
'
,
account_name
,
'
password
'
,
token
)
storage
=
None
def
get_storage
():
global
storage
if
storage
is
None
:
if
USER_HAS_GNOMEKEYRING
:
#FIXME: detect if we're running under GNOME or not
#before deciding to use the GnomeKeyring backend
storage
=
GnomePasswordStorage
()
else
:
storage
=
SimplePasswordStorage
()
return
storage
def
get_password
(
account_name
):
return
get_storage
().
get_password
(
account_name
)
def
save_password
(
account_name
,
password
):
return
get_storage
().
save_password
(
account_name
,
password
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment