-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add admin hash config and warning #79
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: lqsky7 <[email protected]>
src/pwncore/config.py
Outdated
import warnings | ||
from dotenv import load_dotenv | ||
|
||
# Put .env in root of pwncore | ||
dotenv_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), ".env") | ||
if not load_dotenv(dotenv_path): | ||
warnings.warn(f".env file not loaded from {dotenv_path}", RuntimeWarning) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
db_url=os.environ.get("DATABASE_URL", "sqlite://:memory:"),
Load like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest is not needed.
src/pwncore/config.py
Outdated
raw_admin_hash = os.environ.get("PWNCORE_ADMIN_HASH") | ||
if (raw_admin_hash is None): | ||
admin_hash_value = "$2b$12$BjtKkihGhQlOZuLD/KrmuOP27mJ04ldXyzBgtbrNzD9JoPN/DKN1u" | ||
using_default_admin = True | ||
else: | ||
admin_hash_value = raw_admin_hash | ||
using_default_admin = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the default value directly in the get
function call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the default one put the password as pwncore
and hash it.
Signed-off-by: lqsky7 <[email protected]>
src/pwncore/config.py
Outdated
raw_admin_hash = os.environ.get("PWNCORE_ADMIN_HASH", "sqlite://:memory:") | ||
if raw_admin_hash is None: | ||
admin_hash_value = "$2b$12$ZA/l9O96A34QQOlUD48LkesLukw4IAMDih1oV8l.GoEa7TewfeOP2" | ||
using_default_admin = True | ||
else: | ||
admin_hash_value = raw_admin_hash | ||
using_default_admin = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recheck this. It is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import admin_hash directly. No need for raw_admin_hash
or admin_hash_value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't understand os.environ.get("PWNCORE_ADMIN_HASH", "sqlite://:memory:")
second argument of environ.get is what the variable will default to if .env is not found right?
should i do it like this?
admin_hash_value = os.environ.get("PWNCORE_ADMIN_HASH", None)
if admin_hash_value is None:
admin_hash_value = "$2b$12$ZA/l9O96A34QQOlUD48LkesLukw4IAMDih1oV8l.GoEa7TewfeOP2"
using_default_admin = True
src/pwncore/config.py
Outdated
@@ -1,5 +1,7 @@ | |||
import os | |||
from dataclasses import dataclass | |||
import warnings | |||
from dotenv import load_dotenv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not accessed. Remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning is being used, should i just do a print statement instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warnings is fine. dotenv is not required.
Signed-off-by: lqsky7 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case bcrypt
was installed, remove that.
@@ -1,5 +1,7 @@ | |||
import os | |||
import bcrypt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use passlib.hash
> bcrypt
instead.
@@ -42,6 +44,8 @@ | |||
"users_not_found": 24, | |||
} | |||
|
|||
admin_hash_value = os.environ.get("PWNCORE_ADMIN_HASH", bcrypt.hashpw('pwncore'.encode(), bcrypt.gensalt()).decode()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bcrypt.hashpw('pwncore'.encode(), bcrypt.gensalt()).decode()
> bcrypt.hash("pwncore")
No description provided.