bigplum / lua-resty-mongol

A ngx_lua driver for mongodb -- Deprecated for not updating with the mongodb version
198 stars 67 forks source link

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

Open wwwsec opened 8 years ago

wwwsec commented 8 years ago

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

allisthere2love commented 8 years ago

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.

yangzhenyu01 commented 8 years ago

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