1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-10-27 10:43:20 +00:00

add salt for password

This commit is contained in:
nishiki 2016-05-08 12:06:06 +02:00
parent 85c034b8b3
commit 923977ba04

View file

@ -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