Created
June 5, 2022 12:32
-
-
Save nnsense/274614918c84be304b7f607b975289c3 to your computer and use it in GitHub Desktop.
Testing the keyring usage with python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import keyring | |
from keyring.backends import macOS | |
import platform | |
from getpass import getpass | |
from os import getenv | |
from keyrings.cryptfile.cryptfile import CryptFileKeyring | |
if "Darwin" in platform.system(): | |
print("MacOS") | |
kr = macOS.Keyring() | |
else: | |
print("Linux") | |
kr = CryptFileKeyring() | |
try: | |
kr.keyring_key = getenv("KEYRING_PASSWORD") or getpass("Please enter password for encrypted keyring: ") | |
except ValueError: | |
print("FATAL: Wrong password provided") | |
exit() | |
except: | |
print("ERROR") | |
exit() | |
keyring.set_keyring(kr) | |
username = "testing" | |
user_passwd = keyring.get_password(username, "user_password") | |
if user_passwd: | |
print("Password found: " + user_passwd) | |
else: | |
print("No pass found, setting a new one") | |
new_pass = getpass() | |
keyring.set_password(username, "user_password", new_pass) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment