Exemplo n.º 1
0
	def changePassword(self,username,password,newPassword):
		"""
		Change a users' password.
		"""
		if(not username or not password or not newPassword): return False
		if(not self.authenticate(username,password)): return False
		password = util.encrypt_password(password)
		query = "SELECT username,password FROM user WHERE username = '******' AND password = '******'" % (username,password)
		try: row = self.db.get(query)
		except: return False
		if(not row): return False
		newPassword = util.encrypt_password(newPassword)
		update = "UPDATE user SET password = '******' WHERE username = '******'" % (newPassword,username)
		self.db.execute(update)
		if(self.memcache): self.memcache.setAuthentication(username,password)
		return True
Exemplo n.º 2
0
	def registerUser(self,email,username,password):
		"""
		Register a user.
		"""
		if(not email or not username or not password): return False
		password = util.encrypt_password(password)
		query = "INSERT INTO user(username,email,password) VALUES('%s','%s','%s')" % (username,email,password)
		try: self.db.execute(query)
		except: return False
		if(self.memcache): self.memcache.registerUser(email,username)
		return True
Exemplo n.º 3
0
    def changePassword(self, username, password, newPassword):
        """
		Change a users' password.
		"""
        if (not username or not password or not newPassword): return False
        if (not self.authenticate(username, password)): return False
        password = util.encrypt_password(password)
        query = "SELECT username,password FROM user WHERE username = '******' AND password = '******'" % (
            username, password)
        try:
            row = self.db.get(query)
        except:
            return False
        if (not row): return False
        newPassword = util.encrypt_password(newPassword)
        update = "UPDATE user SET password = '******' WHERE username = '******'" % (
            newPassword, username)
        self.db.execute(update)
        if (self.memcache): self.memcache.setAuthentication(username, password)
        return True
Exemplo n.º 4
0
    def registerUser(self, email, username, password):
        """
		Register a user.
		"""
        if (not email or not username or not password): return False
        password = util.encrypt_password(password)
        query = "INSERT INTO user(username,email,password) VALUES('%s','%s','%s')" % (
            username, email, password)
        try:
            self.db.execute(query)
        except:
            return False
        if (self.memcache): self.memcache.registerUser(email, username)
        return True
Exemplo n.º 5
0
	def unregisterUser(self,email,username,password):
		"""
		Unregister a user. Deletes the entry in the user table and all associated tags.
		"""
		if(not email or not username or not password): return False
		if(not self.authenticate(username,password)): return False
		uid = self.userIdForUsername(username)
		if(uid < 0): return False
		deleteq = "DELETE FROM tag WHERE userId = '%s'" % (uid)
		try: self.db.execute(deleteq)
		except: return False
		password = util.encrypt_password(password)
		deleteq = "DELETE FROM user WHERE username = '******' AND email = '%s' AND password = '******'" % (username,email,password)
		try: self.db.execute(deleteq)
		except: return
		if(self.memcache): self.memcache.unregisterUser(email,username)
		return True
Exemplo n.º 6
0
	def authenticate(self,username,password):
		"""
		Find a row with username and password match.
		"""
		if(not username or not password): return False
		auth = False
		if(self.memcache): auth = self.memcache.authenticate(username,password)
		if(auth): return True
		password = util.encrypt_password(password)
		query = "SELECT id, COUNT(id) as totalRows FROM user WHERE username = '******' AND password = '******'" % (username,password)
		row = None
		try: row = self.db.get(query)
		except: return False
		count = int(row["totalRows"])
		if(count < 1): return False
		if(not row): return False
		if(self.memcache): self.memcache.setAuthentication(username,password)
		return row
Exemplo n.º 7
0
    def authenticate(self, username, password):
        """
		Find a row with username and password match.
		"""
        if (not username or not password): return False
        auth = False
        if (self.memcache):
            auth = self.memcache.authenticate(username, password)
        if (auth): return True
        password = util.encrypt_password(password)
        query = "SELECT id, COUNT(id) as totalRows FROM user WHERE username = '******' AND password = '******'" % (
            username, password)
        row = None
        try:
            row = self.db.get(query)
        except:
            return False
        count = int(row["totalRows"])
        if (count < 1): return False
        if (not row): return False
        if (self.memcache): self.memcache.setAuthentication(username, password)
        return row
Exemplo n.º 8
0
    def unregisterUser(self, email, username, password):
        """
		Unregister a user. Deletes the entry in the user table and all associated tags.
		"""
        if (not email or not username or not password): return False
        if (not self.authenticate(username, password)): return False
        uid = self.userIdForUsername(username)
        if (uid < 0): return False
        deleteq = "DELETE FROM tag WHERE userId = '%s'" % (uid)
        try:
            self.db.execute(deleteq)
        except:
            return False
        password = util.encrypt_password(password)
        deleteq = "DELETE FROM user WHERE username = '******' AND email = '%s' AND password = '******'" % (
            username, email, password)
        try:
            self.db.execute(deleteq)
        except:
            return
        if (self.memcache): self.memcache.unregisterUser(email, username)
        return True