Skip to content

Commit

Permalink
if no password given, generate one and return it in an extra field. f…
Browse files Browse the repository at this point in the history
…ixes #772
  • Loading branch information
Tieske committed Dec 13, 2015
1 parent a028d4a commit 4ed8d4a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions kong/plugins/basic-auth/daos.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local BaseDao = require "kong.dao.cassandra.base_dao"
local crypto = require "kong.plugins.basic-auth.crypto"
local utils = require "kong.tools.utils"

local function encrypt_password(password, credential)
credential.password = crypto.encrypt(credential)
Expand All @@ -26,4 +27,20 @@ function BasicAuthCredentials:new(properties)
BasicAuthCredentials.super.new(self, properties)
end

function BasicAuthCredentials:insert(params)
if params.password then
return BasicAuthCredentials.super.insert(self, params)
else
-- No password was provided, so we insert a random generated password
local newpwd = utils.random_string()
params.password = newpwd
local data, err = BasicAuthCredentials.super.insert(self, params)
-- inserting the data has encrypted the password field by now,
-- so add a new field with the generated plain text password
-- which will be returned to the requester
data.plain_password = newpwd
return data, err
end
end

return {basicauth_credentials = BasicAuthCredentials}

0 comments on commit 4ed8d4a

Please sign in to comment.