mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-20 01:50:04 +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
|
||||
# args: id -> the item 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
|
||||
|
||||
# Set a password
|
||||
# args: id -> the item id
|
||||
# password -> the new password
|
||||
def set_password(id, password)
|
||||
salt = MPW::password(Random.rand(4..9))
|
||||
password = "$#{salt}::#{password}"
|
||||
|
||||
@passwords[id] = encrypt(password)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue