• Django自带加密模块的使用

    在Win平台开发Python项目往往因为加密模块不能使用crypt加密模块而感到蛋疼,这次使用Django在Win平台开发项目就又为这个加密模块而发愁。但考虑到Django有用户验证模块,证明它已具备跨平台的加密模块。于是阅读文档,在https://docs.djangoproject.com/en/1.6/topics/auth/passwords/页面发现有这样一段话

    Manually managing a user’s password
    The django.contrib.auth.hashers module provides a set of functions to create and validate hashed password. You can use them independently from the User model.
    check_password(password, encoded)
    If you’d like to manually authenticate a user by comparing a plain-text password to the hashed password in the database, use the convenience function check_password(). It takes two arguments: the plain-text password to check, and the full value of a user’s password field in the database to check against, and returns True if they match, False otherwise. Changed in Django 1.6:
    In Django 1.4 and 1.5, a blank string was unintentionally considered to be an unusable password, resulting in this method returningFalse for such a password.
    make_password(password[, salt, hashers])
    Creates a hashed password in the format used by this application. It takes one mandatory argument: the password in plain-text. Optionally, you can provide a salt and a hashing algorithm to use, if you don’t want to use the defaults (first entry of PASSWORD_HASHERS setting). Currently supported algorithms are: 'pbkdf2_sha256', 'pbkdf2_sha1', 'bcrypt_sha256'(see Using bcrypt with Django), 'bcrypt', 'sha1', 'md5', 'unsalted_md5' (only for backward compatibility) and 'crypt' if you have the crypt library installed. If the password argument is None, an unusable password is returned (a one that will be never accepted by check_password()).

    ...

    READ ALL

  • IE11打不开网页,菜单项变灰

    full

    IE11浏览器突然打不开任何网页

    full

    点击设置按钮大多数设置都是灰的:

    full

    到 控制面板 > 程序和功能 > 打开或关闭window功能 中IE11取消勾选,确定

    full

    ...

    READ ALL

  • MySQL导入sql脚本错误 2006 - MySQL server has gone away

    MySQL导入sql 10M脚本时出错,如图

    full

    Error occured at:2014-03-24 11:42:24
    Line no.:85
    Error Code: 2006 - MySQL server has gone away
    

    最终找到原因,原来是MySQL导入大批量数据的时候超出了默认允许最大的数据包所以就提示2006 - MySQL server has gone away

    于是找到my.cnf,在[mysqld]加入:

    ...

    READ ALL

  • Django1.6访问static内容提示编码错误

    今天用Django搭建一个环境,在访问的时候感觉有点怪

    full

    感觉页面CSS似乎没有被加载进来,于是单独访问某个CSS文件结果浏览器提示

    A server error occurred. Please contact the administrator.

    控制台

    Traceback (most recent call last):
      File "D:\Python27\lib\wsgiref\handlers.py", line 85, in run
        self.result = application(self.environ, self.start_response)
      File "D:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 68, in __call__
        return super(StaticFilesHandler, self).__call__(environ, start_response)
      File "D:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 206, in __call__
        response = self.get_response(request)
      File "D:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 58, in get_response
        return self.serve(request)
      File "D:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 51, in serve
        return serve(request, self.file_path(request.path), insecure=True)
      File "D:\Python27\lib\site-packages\django\contrib\staticfiles\views.py", line 41, in serve
        return static.serve(request, path, document_root=document_root, **kwargs)
      File "D:\Python27\lib\site-packages\django\views\static.py", line 61, in serve
        content_type, encoding = mimetypes.guess_type(fullpath)
      File "D:\Python27\lib\mimetypes.py", line 297, in guess_type
        init()
      File "D:\Python27\lib\mimetypes.py", line 358, in init
        db.read_windows_registry()
      File "D:\Python27\lib\mimetypes.py", line 258, in read_windows_registry
        for subkeyname in enum_types(hkcr):
      File "D:\Python27\lib\mimetypes.py", line 249, in enum_types
        ctype = ctype.encode(default_encoding) # omit in 3.x!
      File "D:\Python27\lib\encodings\utf_8.py", line 16, in decode
        return codecs.utf_8_decode(input, errors, True)
    UnicodeDecodeError: 'utf8' codec can't decode byte 0xb0 in position 1: invalid start byte
    

    ...

    READ ALL

  • MySQL5.6 Using a password on the command line interface can be insecure

    最近把MySQL从5.5升到5.6以后,mysqldump居然不好用了,提示

    [root@qttc ~]# /usr/local/mysql/bin/mysqldump  -uroot -proot db > bak.sql
    Warning: Using a password on the command line interface can be insecure.
    

    这让人有点奇怪,5.5用的一直都很爽,到5.6居然说命令行方式写密码不安全?那密码写哪呢?

    在官网文档找到了原因

    MySQL users should use the following guidelines to keep passwords secure.
    When you run a client program to connect to the MySQL server, it is inadvisable to specify your password in a way that exposes it to discovery by other users. The methods you can use to specify your password when you run client programs are listed here, along with an assessment of the risks of each method. In short, the safest methods are to have the client program prompt for the password or to specify the password in a properly protected option file.

    ...

    READ ALL

  • SWFUpload上传提示Security Error 2049

    很早之前,我写过一篇基于PHP版本的SWFUpload上传组件的文章,最近老是收到不少朋友询问SWFUpload的问题,决定再整理一些最常见的问题整理出来。

    点击hello弹不出选择文件对话框

    这是由于你没有基于HTTP协议访问引起的,你可以把它放到WebServer里试一试,比如Nginx,Apache,Tomcat等等,然后使用http访问页面

    上传文件提示Security Error 2049

    full

    ...

    READ ALL

  • Java sleep和yield区别

    yield和sleep都是作用于当前线程

    yield方法会临时暂停当前正在执行的线程,让有同样优先级等待的线程有资源执行。如果没有正在等待的线程,或者所有正在等待的线程的优先级都比较低,那么该线程会继续运行。执行了yield方法的线程什么时候会继续运行由线程调度器来决定,不同的CPU可能有不同的行为。yield方法不保证当前的线程会暂停或者停止,但是可以保证当前线程在调用yield方法时会放弃CPU。

    所以总结下来

    • yield和sleep都不释放锁
    • sleep只是暂停,之后继续
    • yield是让出CPU资源,等待下一次资源调度继续

    ...

    READ ALL

  • CentOS开机卡在进度条的解决方法

    CentOS开机的时候卡在进度条一直进不去

    full

    这看不出开机启动卡在哪里,只好重启按住"e"键,进入启动菜单

    full

    接着按e进入编辑第一项

    full

    然后移动到第二项kernel...接着按e进入编辑

    ...

    READ ALL

  • IE8动态创建script标签onload不工作

    今天做项目,发现一个奇怪的问题,动态创建的script标签在IE8下无法触发onload事件?请看示例代码

    var loadJs = function (src, fun) {
      var script = null;
      script = document.createElement('script');
      script.type = 'text/javascript';
      script.src = src;
      if (typeof fun === 'function') {
        script.onload = fun;
      }
    
      document.getElementsByTagName('head')[0].appendChild(script);
    };
     
    loadJs('http://code.jquery.com/jquery-1.11.0.min.js', function () {
      console.log('From jQuery');
    });
     
    loadJs('test.js', function () {
      console.log('From test.js');
    });
    

    ...

    READ ALL

  • Python一次has_key蛋疼的错误调试

    今晚像往常一样打开Aptana写Python程序时,一个has_key调用报错了,代码如下

    info = {}
    info.has_key("key")
    

    控制台

    Traceback (most recent call last):
      File "D:\workspace\aptana\test\main.py", line 8, in <module>
        print(info.has_key("email"))
    AttributeError: 'dict' object has no attribute 'has_key'
    

    ...

    READ ALL