Upload
darshan-j
View
52
Download
0
Embed Size (px)
Citation preview
PyMongo Passw*rd Change Made Easy
-Darshan JDBA & Python Entu
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.
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
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
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
…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.
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.
…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 .
PyMongo
…PyMongo
PyMongo is a Python distribution containing tools for working with MongoDB, and is the recommended way to work with MongoDB from Python.
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.
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
…FlowChart
..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)
..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)
@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)
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
Q&A