Project for Python cert class
passwordManager is a web service uses to manager passwords. You can create users, with is a username/password combination
with optionl phrase.Userames are unique. Once user is created,you can add passwords associated with the user. the password contain a unique name
password and optional phrase. passwrords are encrypted and stored.
- pycrypto
- flask
Password Manager is a REST API running as a Flask app. To run Check out the code, make sure prerequisites are installed. Then start the service.py file as flask app or deploy service.py(with supporting files) to a service like apache or nginix
Example | http://localhost:5000/ |
---|---|
Exected result | '200 OK if service up |
Expected Result JSON | {'status': 'Service Up'} |
Expected JSON of following format in the body of request
{'username' : 'someUserName',
'password' : 'Some_Password',
'phrase' : 'some optional phrase'
}
Example | http://localhost:5000/addUser (with User json in body) |
---|---|
Exected result | 200 OK if user is created successfully |
400 Bad Request with matching Error message if user is not created successfully |
Following are the rules for new user to be added/created.
- UserName must be unique, if a userName already exists then 400 Bad Request is returned
with Error message
{'username' : 'Key already exists'}
- The json send in the requst must be valid and must pass user validation
- user josn must have atlest username and password, if not 400 Bad Requst is returned
with error message
{'error': 'Invalid Data'}
- user josn must have atlest username and password, if not 400 Bad Requst is returned
with error message
- Following are user validation rules
1. userName validation
- userName length must be between 4 and 50 chars
- userName must be alpha numberic only
- If username validation fails, 400 Bad Request is retruned with appropriate error
eg :
{'error': {'username': ' can only contain alphabets and digits'}}
2. password validation - password length must be between 8 and 50 chars
- password must be alpha numeric with special chars _ ,@ , #, $ and * allowed
- for a password to be valid it must have 3 for the following 4
- a uppercase letter
- a lowercase letter
- a number
- atlest one of the allowed special char
- If password validation fails, 400 Bad Request is returned with appropriate error
eg :
{'error': {'password': ' must be between 8 an 50 chars'}}
3. phrase validation - phrase length must be between 4 and 100 chars
- phrase must be alpha numberic with spaces allowed
- If phrase validation fails, 400 Bad Request is retruned with appropriate error
eg :
{'error': {'phrase': ' must be between 4 an 100 chars'}}
Example | http://localhost:5000/getUser/user1/Password1 |
---|---|
Exected result | 200 OK - if user exists name and password from URL |
404 Not Found - if user doesnt exist |
- For a 200 OK response the user JSON is retrned in body of resposne
the user json contains the Phrase stored on user, username and password is not returned.
eg :
{'result': 'found', 'phrase' : 'User1 info'}
- 404 Not found is returned if there is no user with the Username in the URL, or
The user exists but password is incorrect. appropritae message is retrned too.
eg.
{'result': 'Not found','msg' : 'User data not found'}
Expected JSON of following format in the body of request
{'name' : 'passwordName1',
'password' : 'some password',
'phrase' : 'shome phrase 1'
}
Example | http://localhost:5000/addPassword/User1/Password1 (with password json in body) |
---|---|
Exected result | 200 OK if password is created successfully |
400 Bad Request with matching Error message if password is not created successfully |
Following are the rules for new password to be added/created.
- password name name must be unique, if a name already exists then 400 Bad Request is returned
with Error message
{'name ' : 'Key already exists'}
- There must be an existing user with matchign userName and password from URL. If there is no user
with username or password in URL is incorrect then 400 Bad Request is returned with Error
messgae
{'error' : 'No user found for usernamepassword combination'}
- The json send in the requst must be valid and must pass password validation
- passwordInfo josn must have atlest name and password, if not 400 Bad Requst is returned
with error message
{'error': 'Invalid Data'}
- passwordInfo josn must have atlest name and password, if not 400 Bad Requst is returned
with error message
- Following are passwordInfo validation rules
1. Name validation
- name length must be between 4 and 50 chars
- name must be alpha numberic only
- If username validation fails, 400 Bad Request is retruned with appropriate error
eg :
{'error': {'name': ' can only contain alphabets and digits'}}
2. password validation - password length must be atleast 4 chars exluding spaces
- password can contain any ascii char inluding space
- If password validation fails, 400 Bad Request is returned with appropriate error
eg :
{'error': {'password': ' length must be atlest 4 chars'}}
3. phrase validation - phrase length must be between 4 and 50 chars
- phrase must be alpha numberic, spaces are allowed
- If phrase validation fails, 400 Bad Request is retruned with appropriate error
eg :
{'error': {'phrase': ' must be between 4 an 50 chars'}}
Example | http://localhost:5000/getPassword/user1/Password1/data1 |
---|---|
Exected result | 200 OK - if password exists name for username and password URL |
404 Not Found - if password doesnt exist | |
400 Bad Request - if username and/or passwowd is incorrect |
- For a 200 OK response the password JSON is retrned in body of resposne
the passwrod json contains the passwordName, decryted password and phrase.
eg :
{'name': 'data1', 'password': 'some password', 'phrase' : 'password for data 1'}
- 404 Not found is returned if there is no password with the name in the URL with following
error message
{'result': 'Not found','msg' : 'no pasword found with key'}
- 400 Bad Request is returned if username and/or password in URL is invaid, ie. no user
exists with data in URL,following error message is returned
{'error': {'msg': invalid uer info passed'}}
Example | http://localhost:5000/getPassword/user1/Password1/name/data1 |
---|---|
Exected result | 200 OK - if there is atlest one paswordInfo with search criteria |
400 Bad Request - if username and/or passwowd is incorrect | |
400 Bad Request - if search Key is invalid |
- Like getPassword call, if username and/or password in URL is incorrect, then 400 Bad request is returned
- Allowed searchKeys are 'name' or 'phrase', if key doenst match allowed searchKeys then 400 Bad Request
is returned with error message
{'Error': 'invalid search key'}
- The searchName must be atlest 2 chars, if not 400 Bad Request is retruend with error message
{'Error': ' search string is too short'}
- If no passwordInfos are found with search criteria then 200 OK is retruend with following JSON
{'Result': 'No Data Found with search criteria'}
- If passwordInfos are found with search criteria then 200 Ok is retruend with a JSON ARRAY of all the passwords