0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/client/examples/authTest.cpp
Eliot Horowitz 120f859704 change password digest
from md5( "mongo" + pwd )
to md5( username + ":mongo:" + pwd )
2009-01-30 15:06:12 -05:00

32 lines
748 B
C++

// authTest.cpp
#include <iostream>
#include "client/dbclient.h"
using namespace mongo;
int main() {
DBClientConnection conn;
string errmsg;
if ( ! conn.connect( "127.0.0.1" , errmsg ) ) {
cout << "couldn't connect : " << errmsg << endl;
throw -11;
}
{ // clean up old data from any previous tests
conn.remove( "test.system.users" , emptyObj );
}
conn.insert( "test.system.users" , BSON( "user" << "eliot" << "pwd" << conn.createPasswordDigest( "eliot" , "bar" ) ) );
errmsg.clear();
bool ok = conn.auth( "test" , "eliot" , "bar" , errmsg );
if ( ! ok )
cout << errmsg << endl;
assert( ok );
assert( ! conn.auth( "test" , "eliot" , "bars" , errmsg ) );
}