class TestPasswordValidator(unittest.TestCase): def setUp(self): print self._testMethodName + " begins now......" self.validator = UserValidator() def test_password_empty_fail(self): self.validator.setPassword("") self.assertFalse(self.validator.passwordValidate()) def test_password_onlynum_fail(self): self.validator.setPassword("12345") self.assertFalse(self.validator.passwordValidate()) def test_password_onlyletter_fail(self): self.validator.setPassword("tiAADfes") self.assertFalse(self.validator.passwordValidate()) def test_password_short_fail(self): self.validator.setPassword("tA12") self.assertFalse(self.validator.passwordValidate()) def test_password_valid_success(self): self.validator.setPassword("ting123!A") self.assertTrue(self.validator.passwordValidate()) def tearDown(self): del self.validator
def post(self, request): validator = UserValidator() # validate input encryptpw = EncryptionPassword() # encrypt password if "username" not in request.session: regInfo = json.loads(request.body) validator.setUsername(regInfo["un"]) validator.setPassword(regInfo["pw"]) encryptpw.setPassword(regInfo["pw"]) if validator.usernameValidate() == True and validator.passwordValidate() == True: with UserModel() as usermodel: usermodel.setUsername(regInfo["un"]) rows = usermodel.queryRegister() if rows == None: hashList = encryptpw.encryptPw() hashPW = hashList[0] newSalt = hashList[1] with UserModel() as usermodel: usermodel.setUsername(regInfo["un"]) usermodel.setPassword(hashPW) usermodel.setSalt(newSalt) usermodel.setEmail(regInfo["em"]) usermodel.setFirstname(regInfo["fn"]) usermodel.setLastname(regInfo["ln"]) usermodel.insertRegister() request.session["username"] = regInfo["un"] return HttpResponse(json.dumps({'r':"success",'un':request.session["username"]}), content_type="application/json") else: return HttpResponse(json.dumps({'r':"exist"}), content_type="application/json") else: return HttpResponse(json.dumps({'r':"notvalid"}), content_type="application/json") else: return HttpResponse(json.dumps({'r':"loggedin",'un':request.session["username"]}), content_type="application/json")
def post(self, request): validator = UserValidator() # validate input encryptpw = EncryptionPassword() # encrypt password if "username" not in request.session: regInfo = json.loads(request.body) logging.info(regInfo) validator.setUsername(regInfo['un']) validator.setPassword(regInfo['pw']) encryptpw.setPassword(regInfo['pw']) if validator.usernameValidate() == True and validator.passwordValidate() == True: with UserModel() as usermodel: usermodel.setUsername(regInfo['un']) salt = usermodel.querySalt()[11] hashPW = encryptpw.encryptPw(salt)[0] usermodel.setPassword(hashPW) rows = usermodel.queryLogin() logging.info(rows) if rows != None: usermodel.updateLoginDate() if rows != None: request.session["username"] = regInfo['un'] return HttpResponse(json.dumps({'r':1,'un':request.session["username"]}), content_type="application/json") # successfully login else: return HttpResponse(json.dumps({'r':0}), content_type="application/json") # incorrect username/password else: return HttpResponse(json.dumps({'r':3}), content_type="application/json")# username/password not validated else: return HttpResponse(json.dumps({'r':2,'un':request.session["username"]}), content_type="application/json") # already login
def post(self, request): requestCon = json.loads(request.body) uservalidator = UserValidator() uservalidator.setPassword(requestCon["pw"]) encryptpw = EncryptionPassword() encryptpw.setPassword(requestCon["pw"]) hashList = encryptpw.encryptPw() newPass = hashList[0] newSalt = hashList[1] if uservalidator.passwordValidate() == True: with UserModel() as usermodel: usermodel.setUsername(requestCon["un"]) usermodel.updateSalt(newSalt) usermodel.resetPassword(newPass) return HttpResponse("success", content_type="text/plain") else: return HttpResponse("notvalid", content_type="text/plain")
def post(self, request): validator = UserValidator() # validate input encryptpw = EncryptionPassword() # encrypt password if "username" not in request.session: regInfo = json.loads(request.body) validator.setUsername(regInfo["un"]) validator.setPassword(regInfo["pw"]) encryptpw.setPassword(regInfo["pw"]) if validator.usernameValidate( ) == True and validator.passwordValidate() == True: with UserModel() as usermodel: usermodel.setUsername(regInfo["un"]) rows = usermodel.queryRegister() if rows == None: hashList = encryptpw.encryptPw() hashPW = hashList[0] newSalt = hashList[1] with UserModel() as usermodel: usermodel.setUsername(regInfo["un"]) usermodel.setPassword(hashPW) usermodel.setSalt(newSalt) usermodel.setEmail(regInfo["em"]) usermodel.setFirstname(regInfo["fn"]) usermodel.setLastname(regInfo["ln"]) usermodel.insertRegister() request.session["username"] = regInfo["un"] return HttpResponse(json.dumps({ 'r': "success", 'un': request.session["username"] }), content_type="application/json") else: return HttpResponse(json.dumps({'r': "exist"}), content_type="application/json") else: return HttpResponse(json.dumps({'r': "notvalid"}), content_type="application/json") else: return HttpResponse(json.dumps({ 'r': "loggedin", 'un': request.session["username"] }), content_type="application/json")
def post(self, request): validator = UserValidator() # validate input encryptpw = EncryptionPassword() # encrypt password if "username" not in request.session: regInfo = json.loads(request.body) logging.info(regInfo) validator.setUsername(regInfo['un']) validator.setPassword(regInfo['pw']) encryptpw.setPassword(regInfo['pw']) if validator.usernameValidate( ) == True and validator.passwordValidate() == True: with UserModel() as usermodel: usermodel.setUsername(regInfo['un']) salt = usermodel.querySalt()[11] hashPW = encryptpw.encryptPw(salt)[0] usermodel.setPassword(hashPW) rows = usermodel.queryLogin() logging.info(rows) if rows != None: usermodel.updateLoginDate() if rows != None: request.session["username"] = regInfo['un'] return HttpResponse( json.dumps({ 'r': 1, 'un': request.session["username"] }), content_type="application/json") # successfully login else: return HttpResponse(json.dumps({'r': 0}), content_type="application/json" ) # incorrect username/password else: return HttpResponse(json.dumps({'r': 3}), content_type="application/json" ) # username/password not validated else: return HttpResponse( json.dumps({ 'r': 2, 'un': request.session["username"] }), content_type="application/json") # already login
def post(self, request): validator = UserValidator() # validate input encryptpw = EncryptionPassword() # encrypt password if "username" in request.session: regInfo = json.loads(request.body) validator.setPassword(regInfo["newpass"]) encryptpw.setPassword(regInfo["oldpass"]) if regInfo["newpass"] == "" or validator.passwordValidate( ) == True: with UserModel() as usermodel: usermodel.setUsername(request.session["username"]) salt = usermodel.querySalt()[11] hashPW = encryptpw.encryptPw(salt)[0] usermodel.setPassword(hashPW) rows = usermodel.queryLogin() if rows != None: hashList = encryptpw.encryptPw() newoldPW = encryptpw.encryptPw()[0] newSalt = encryptpw.encryptPw()[1] if regInfo["newpass"] == "": newPW = newoldPW else: encryptpw.setPassword(regInfo["newpass"]) newPW = encryptpw.encryptPw(newSalt)[0] with UserModel() as usermodel: usermodel.setUsername(request.session["username"]) usermodel.setPassword(newPW) usermodel.setEmail(regInfo["em"]) usermodel.setSalt(newSalt) usermodel.setFirstname(regInfo["fn"]) usermodel.setLastname(regInfo["ln"]) usermodel.updateRegister() return HttpResponse("success", content_type="text/plain") else: return HttpResponse("notcorrect", content_type="text/plain") else: return HttpResponse("notvalid", content_type="text/plain") else: return HttpResponse("notlogin", content_type="text/plain")
def post(self, request): validator = UserValidator() # validate input encryptpw = EncryptionPassword() # encrypt password if "username" in request.session: regInfo = json.loads(request.body) validator.setPassword(regInfo["newpass"]) encryptpw.setPassword(regInfo["oldpass"]) if regInfo["newpass"] == "" or validator.passwordValidate() == True: with UserModel() as usermodel: usermodel.setUsername(request.session["username"]) salt = usermodel.querySalt()[11] hashPW = encryptpw.encryptPw(salt)[0] usermodel.setPassword(hashPW) rows = usermodel.queryLogin() if rows != None: hashList = encryptpw.encryptPw() newoldPW = encryptpw.encryptPw()[0] newSalt = encryptpw.encryptPw()[1] if regInfo["newpass"] == "": newPW = newoldPW else: encryptpw.setPassword(regInfo["newpass"]) newPW = encryptpw.encryptPw(newSalt)[0] with UserModel() as usermodel: usermodel.setUsername(request.session["username"]) usermodel.setPassword(newPW) usermodel.setEmail(regInfo["em"]) usermodel.setSalt(newSalt) usermodel.setFirstname(regInfo["fn"]) usermodel.setLastname(regInfo["ln"]) usermodel.updateRegister() return HttpResponse("success", content_type="text/plain") else: return HttpResponse("notcorrect", content_type="text/plain") else: return HttpResponse("notvalid", content_type="text/plain") else: return HttpResponse("notlogin", content_type="text/plain")