lua-resty-mongol icon indicating copy to clipboard operation
lua-resty-mongol copied to clipboard

I use mongodb 3.x,db:auth(user,pwd) can't work.Is this program need upgrade?

Open wwwsec opened this issue 9 years ago • 2 comments

local mongo = require "resty.mongol" local host_info = { host="192.168.1.2", port=27017, username="ttt", password="ttt" } conn = mongo:new() conn:set_timeout(2000) ok, err = conn:connect(host_info["host"], host_info["port"]) ngx.say(ok,err) -- 1 nil if not ok then ngx.log("connect failed: "..err) end local db = conn:new_db_handle("ttt") ok, err = db:auth(host_info["username"], host_info["password"]) ngx.say(ok, err) -- nil lauth failed col = db:get_col("tt") r = col:find_one({a=1}) if r == nil then return false else ngx.say(r["_id"]) return true end

wwwsec avatar Dec 21 '15 15:12 wwwsec

I've got the same issue here. No success in Mongo 3.x auth, got a Mongo 2.6 running and managed to connect with no problems using the same code.

allisthere2love avatar Feb 15 '16 18:02 allisthere2love

You must modify the source code,because Mongo 2.6 use md5 Encrypt,Mongo 3.x use sha1 Encrypt。 modify the dbmt.lua file.

local function pass_digest ( username , password ) return ngx.md5(username .. ":mongo:" .. password) end

yangzhenyu01 avatar Jun 08 '16 09:06 yangzhenyu01