def decoderpass(s):
	LOG.setup_logging_to_file()
	try:
		sup=base64.decodebytes(s.encode()).decode()
	except Exception as a:
		setattr(a,'message','Unsuccessful decryption')
		LOG.log_exception(a)
	else:
		return sup.strip()
Example #2
0
def closeCon(con, cur):
    try:
        con.close()
        cur.close()
    except Exception as a:
        setattr(a, 'message', 'Calling Exception')
        LOG.log_exception(a)
    else:
        LOG.log_debug("Closed Connection to DB")
Example #3
0
def cursModule(s):
    try:
        con = s
        cursr = con.cursor()
    except Exception as a:
        setattr(a, 'message', 'Calling Exception')
        LOG.log_exception(a)
    else:
        LOG.log_debug("Cursor opened")
        return cursr
Example #4
0
def connModule():
    dbpp, dbp, fl = 'Start', list(), 0
    try:
        with open('../properties/DB_DETAILS.properties', 'r') as db:
            while len(dbpp) != 0:
                dbpp = db.readlines(2)
                dbp.append(dbpp)
        dbp.pop()
        for i in range(6, 11):
            if len(dbp[i]) != 1:
                fl = 1
                break
        if len(dbp) != 11 or fl != 0:
            raise CE.DBException(
                msg=
                "Incorrect Properties file, check properties/DB_DETAILS.properties",
                dberr=str(DBERR.pgerror) + str(DBERR.pgcode))
    except Exception as a:
        setattr(a, 'message', 'Calling Exception')
        LOG.log_exception(a)
    else:
        '''print(dbp)'''
        dbhost = dbp[6][0][dbp[6][0].find(":") + 1:].strip()
        dbport = int(dbp[7][0][dbp[7][0].find(":") + 1:].strip())
        dbname = dbp[8][0][dbp[8][0].find(":") + 1:].strip()
        dbuser = dbp[9][0][dbp[9][0].find(":") + 1:].strip()
        dbpass = dbp[10][0][dbp[10][0].find(":") + 1:].strip()
        dbpass = PE.decoderpass(dbpass)
        '''print(dbhost, dbport, dbname, dbuser, dbpass)'''
        try:
            conn = psycopg2.connect(user=dbuser,
                                    password=dbpass,
                                    host=dbhost,
                                    port=dbport,
                                    database=dbname)
        except Exception as a:
            setattr(a, 'message', 'Calling Exception')
            LOG.log_exception(a)
        else:
            LOG.log_debug(
                "Connection to {DB} DB is successful with {user} on {host}:{port}"
                .format(DB=dbname, user=dbuser, host=dbhost, port=dbport))
            return conn
	except Exception as a:
		setattr(a,'message','Unsuccessful decryption')
		LOG.log_exception(a)
	else:
		return sup.strip()
#encodes a given plain text into an obscured plain text
def encoderpass(s):
	LOG.setup_logging_to_file()
	try:
		sup=base64.encodebytes(s.encode()).decode()
	except Exception as a:
		setattr(a,'message','Unsuccessful encryption')
		LOG.log_exception(a)
	else:
		return sup.strip()
if __name__ == '__main__':
	LOG.setup_logging_to_file(filename="../logs/user_encoder.log")
	try:
		pswd=input("Enter your password to be encrypted :\n")
		if len(pswd)>0:
			print(encoderpass(pswd))
			logg="Password encoding successful"
		else:
			logg="Password encoding Unsuccessful"
			raise CE.UnsuccessfulEncryption(msg="Invalid password or blank")
	except Exception as a:
		setattr(a,'message','Calling UnsuccessfulEncryption')
		LOG.log_exception(a)
	finally:
		LOG.log_debug(logg)
		input()