19
PyMongo Passw*rd Change Made Easy -Darshan J DBA & Python Entu

Pymongo password change made easy

Embed Size (px)

Citation preview

Page 1: Pymongo password change made easy

PyMongo Passw*rd Change Made Easy

-Darshan JDBA & Python Entu

Page 2: Pymongo password change made easy

Who Am I

Name Darshan, I deal with Database so I am DBA. I myself elect as programing entu.

Having 30+ Months of experience in Database Administration.

Recently got exposure to Python. Having Good hands on in Shell script,

JavaScript and Python Script.

Page 3: Pymongo password change made easy

Agenda

What is MongoD

B

What MongoDB Lag with

How I over come with

PYTHON

What PyMongo

About Bottle

framework

Code and Algorith

m

Where It is useful Q&A

Page 4: Pymongo password change made easy

What is MongoDB

MongoDB is open source , document based Database.

Very popular now a days for its unique feature

high performance, high availability, and easy scalability.

Documents (objects) map nicely to programming language data types

Page 5: Pymongo password change made easy

What MongoDB Lag with

MongoDB is awesome Database. Every great software will be one or

more Lag Password Complexity ( At least one

capital letter, one small letter, one letter and special character )

Every shift starts with resetting users password, An UI needed to give a platform to end-user to reset their password

Page 6: Pymongo password change made easy

…MongoDB Lag

Web Interface is the easiest way to deploy and reach all the end-user.

Password can be reset for a user particular server and particular Database.

Page 7: Pymongo password change made easy

How I over come with PYTHON

Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language.

It has always been possible to use Python for creating web sites but it was a rather tedious task. Therefore, many frameworks and helper tools have been created to faster and more robust sites.

Page 8: Pymongo password change made easy

…Pyton

Python Having Lot of core programming Benefits, easier logic to implement and easier to understand.

Python used to connect with MongoDB using PyMongo Driver.

I needed a web based UI platform, python has lot of Framework to use .

Page 9: Pymongo password change made easy

PyMongo

Page 10: Pymongo password change made easy

…PyMongo

PyMongo is a Python distribution containing tools for working with MongoDB, and is the recommended way to work with MongoDB from Python.

Page 11: Pymongo password change made easy

About Bottle framework

Bottle is a fast, simple and lightweight WSGI micro web-framework for Python.

It is distributed as a single file module and has no dependencies other than the Python Standard Library.

Page 12: Pymongo password change made easy

Code and Algorithm

Algorithm is simple Host the application in server and share the

URL When user hit the url , it takes username

from the windows login(java script) Asks user to select the DB server. Lists the DB reside in that server. Asks for the New Password Checks the complexity meets requirement Resets the Password

Page 13: Pymongo password change made easy

…FlowChart

Page 14: Pymongo password change made easy

..codes

#!/usr/bin/env pythonimport bottle, pymongofrom pymongo import MongoClientbottle.TEMPLATE_PATH.insert(0,'/home/mongo/darsh/views')from bottle import route

@route('/')def home_page(): try: con = pymongo.MongoClient("mongodb://username:[email protected]:port/?authMechanism=PLAIN&authSource=$external") db='svrlst' svr = con[db].server.distinct("iphost") con.close() return bottle.template('change_pwd',svrname=svr) except Exception, ex: return bottle.template('error',exc=ex)

Page 15: Pymongo password change made easy

..code

@bottle.post('/chgpwd')def chgpwd(): username = bottle.request.forms.get("username") svrnames = bottle.request.forms.get("svid") try: con = pymongo.MongoClient("mongodb://username:[email protected]:port/?authMechanism=PLAIN&authSource=$external") db1 = con.database_names() con.close() return bottle.template('change_pwds',dbs=db1,usrn=username,svrn=svrnames) except Exception, ex: return bottle.template('error',exc=ex)

Page 16: Pymongo password change made easy

@bottle.post('/chgpsd')def chgpsd(): try: username = bottle.request.forms.get("username") svrnames = bottle.request.forms.get("svrname") db1 = str(bottle.request.forms.get("dbid")) pswd = str(bottle.request.forms.get("password")) con = pymongo.MongoClient("mongodb://username:[email protected]:port/dbname”) answer = con['admin'].system.users.find({"user":username,"db":db1}).count() if answer == 1: con[db1].add_user(username,pswd) return bottle.template('changed',usr=username,svr=svrnames,dbs=db1) else: return bottle.template('nochange',usr=username,dbs=db1,svr=svrnames) con.close() except Exception, ex: return bottle.template('error',exc=ex)

bottle.run(reloader=True,debug=True,host=“127.0.0.1",port=8080)

Page 17: Pymongo password change made easy

Where it is useful

I work as a DBA and resetting password all the day is only not my job

It will be usefull when you having quite big users of Database, keep sending you ticket for reset password

Avoid lot of junk work and time

Page 18: Pymongo password change made easy

Q&A

Page 19: Pymongo password change made easy