mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-21 10:20:05 +00:00
add salt for password
This commit is contained in:
parent
85c034b8b3
commit
923977ba04
1 changed files with 10 additions and 1 deletions
|
@ -132,13 +132,22 @@ class MPW
|
||||||
# Get a password
|
# Get a password
|
||||||
# args: id -> the item id
|
# args: id -> the item id
|
||||||
def get_password(id)
|
def get_password(id)
|
||||||
return decrypt(@passwords[id])
|
password = decrypt(@passwords[id])
|
||||||
|
|
||||||
|
if /^\$[a-zA-Z0-9]{4,9}::(?<password>.+)$/ =~ password
|
||||||
|
return Regexp.last_match('password')
|
||||||
|
else
|
||||||
|
return password
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set a password
|
# Set a password
|
||||||
# args: id -> the item id
|
# args: id -> the item id
|
||||||
# password -> the new password
|
# password -> the new password
|
||||||
def set_password(id, password)
|
def set_password(id, password)
|
||||||
|
salt = MPW::password(Random.rand(4..9))
|
||||||
|
password = "$#{salt}::#{password}"
|
||||||
|
|
||||||
@passwords[id] = encrypt(password)
|
@passwords[id] = encrypt(password)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue