示例#1
0
文件: user.py 项目: 20after4/Yaki
 def setpassword(self,passwd):
   if passwd:
     string = self.userid+passwd
     if type(string) is unicode:
       string=string.encode("UTF-8")
     self.__passwordhash=p3.p3_encrypt(string,self.escrow)
   else:
     self.__passwordhash=None
示例#2
0
    def protect_value(self, value, mode=0):
        if mode == 0:
            # encrypt
            if crypt != None and self._secretKey != None:
                cipher = crypt.p3_encrypt(value, self._secretKey)
                return base64.b64encode(cipher)
            elif self._hideData is True:
                return base64.b64encode(value)
        else:
            # decrypt
            if crypt != None and self._secretKey != None:
                cipher = base64.b64decode(value)
                return crypt.p3_decrypt(cipher, self._secretKey)
            elif self._hideData is True:
                return base64.b64decode(value)

        return value
示例#3
0
    def protect_value(self, value, mode=0):
        if mode == 0:
            # encrypt
            if crypt != None and self._secretKey != None :
                cipher = crypt.p3_encrypt(value, self._secretKey)
                return base64.b64encode(cipher)
            elif self._hideData is True:
                return base64.b64encode(value)
        else:
            # decrypt
            if crypt != None and self._secretKey != None :
                cipher = base64.b64decode(value)
                return crypt.p3_decrypt(cipher, self._secretKey)
            elif self._hideData is True:
                return base64.b64decode(value)

        return value
示例#4
0
    def protect_value(self, value, mode=0, section=None):
        if self._secretSections is not None and section is not None:
            for s in self._secretSections:
                if section.startswith(s):
                    break
            else:
                return value

        if mode == 0:
            # encrypt
            if crypt != None and self._secretKey != None:
                cipher = crypt.p3_encrypt(value, self._secretKey)
                return base64.b64encode(cipher)
            elif self._hideData is True:
                return base64.b64encode(value)
        else:
            # decrypt
            if crypt != None and self._secretKey != None:
                cipher = base64.b64decode(value)
                return crypt.p3_decrypt(cipher, self._secretKey)
            elif self._hideData is True:
                return base64.b64decode(value)

        return value
示例#5
0
    def protect_value(self, value, mode=0, section=None):
        if self._secretSections is not None and section is not None:
            for s in self._secretSections:
                if section.startswith(s):
                    break
            else:
                return value
            
        if mode == 0:
            # encrypt
            if crypt != None and self._secretKey != None :
                cipher = crypt.p3_encrypt(value, self._secretKey)
                return base64.b64encode(cipher)
            elif self._hideData is True:
                return base64.b64encode(value)
        else:
            # decrypt
            if crypt != None and self._secretKey != None :
                cipher = base64.b64decode(value)
                return crypt.p3_decrypt(cipher, self._secretKey)
            elif self._hideData is True:
                return base64.b64decode(value)

        return value
示例#6
0
 def writeFile(self, fileRef, updateInfo=True):
     """Write file - raises IOError on failure"""
     lines = [u'<?xml version="1.0" encoding="utf-8" ?>']
     if self.xlstLink:
         lines.append(u'<?%s?>' % self.xlstLink)
     lines.extend(self.root.branchXml([], True))
     text = '\n'.join(lines).encode('utf-8')
     try:
         f = self.getWriteFileObj(fileRef, self.compressFile)
     except IOError:
         print 'Error - could not write file'
         raise
     filePath = unicode(f.name, sys.getfilesystemencoding())
     if self.encryptFile:
         key = filePath.encode(sys.getfilesystemencoding())
         password = TreeDoc.passwordDict.get(key, '')
         if not password:
             if key.endswith('~'):   # for auto-save filename
                 password = TreeDoc.passwordDict.get(key[:-1], '')
             if not password:
                 raise PasswordError, 'Missing password'
         text = encryptPrefix + p3.p3_encrypt(text, password)
     try:
         f.write(text)
     except IOError:
         print 'Error - could not write file', \
               filePath.encode(globalref.localTextEncoding)
         raise
     f.close()
     if filePath.endswith('.gz'):
         self.compressFile = True
     if updateInfo:
         self.modified = False
         self.tlVersion = __version__
         self.fileName = filePath
         self.fileInfoFormat.updateFileInfo()
示例#7
0
 def writeFile(self, fileRef, updateInfo=True):
     """Write file - raises IOError on failure"""
     lines = [u'<?xml version="1.0" encoding="utf-8" ?>']
     if self.xlstLink:
         lines.append(u'<?%s?>' % self.xlstLink)
     lines.extend(self.root.branchXml([], True))
     text = '\n'.join(lines).encode('utf-8')
     try:
         f = self.getWriteFileObj(fileRef, self.compressFile)
     except IOError:
         print 'Error - could not write file'
         raise
     filePath = unicode(f.name, sys.getfilesystemencoding())
     if self.encryptFile:
         key = filePath.encode(sys.getfilesystemencoding())
         password = TreeDoc.passwordDict.get(key, '')
         if not password:
             if key.endswith('~'):  # for auto-save filename
                 password = TreeDoc.passwordDict.get(key[:-1], '')
             if not password:
                 raise PasswordError, 'Missing password'
         text = encryptPrefix + p3.p3_encrypt(text, password)
     try:
         f.write(text)
     except IOError:
         print 'Error - could not write file', \
               filePath.encode(globalref.localTextEncoding)
         raise
     f.close()
     if filePath.endswith('.gz'):
         self.compressFile = True
     if updateInfo:
         self.modified = False
         self.tlVersion = __version__
         self.fileName = filePath
         self.fileInfoFormat.updateFileInfo()
示例#8
0
def encrypt(d):
    """ encrypts dictionary to url-safe string """
    return b64encode(p3_encrypt(urlencode(d), settings.SECRET_KEY), B64_ALTCHARS)
示例#9
0
文件: user.py 项目: 20after4/Yaki
 def checkPassword(self, password):
   string = self.userid+password
   if type(string) is unicode:
     string=string.encode("UTF-8")
   return p3.p3_encrypt(string,self.escrow) == self.__passwordhash