Neo4j校验密码生成代码(Python)

在Neo4j的数据目录下有一个dbms目录,里面存储的是身份校验文件auth

[root@datanode data]# ll
total 0
drwxr-xr-x 3  112 nfsnobody 21 Jan 29 14:34 databases
drwxr-xr-x 2 root root      17 Jan 29 14:36 dbms

[root@datanode dbms]# ls
auth

查看auth文件:

[root@datanode dbms]# cat auth
neo4j:SHA-256,0A9FC5A9A9C368A3FD2E41F9BB024AAA3CA8808B3428A4EE2D72B13703A7AD5E,FADA2AD5718A00B0DAB07735FFD16038:

文件的内容比较简单,形式是“用户名:加密算法,<根据原始密码生成的密码>,<加密的salt盐>”。如果忘记密码或者想修改密码时,可以手工配置或替换此文件。Python代码如下:

Python 3.x:

import hashlib
import codecs

username = input("please input your username: ")
passwd = input("please input your password: ")
salt = input("please input salt: ")

salt_byte = bytes(salt.encode())
passwd_byte = codecs.encode(passwd.encode(), 'hex')

salt_pass = bytearray.fromhex((salt_byte + passwd_byte).decode())

print(username + ":" + "SHA-256," + hashlib.sha256(salt_pass).hexdigest().upper() + "," + salt.upper() + ":")

Python 2.x:

from __future__ import print_function
import hashlib
import codecs

username = raw_input("please input your username: ")
passwd = raw_input("please input your password: ")
salt = raw_input("please input salt: ")

salt_byte = bytes(salt.encode())
passwd_byte = codecs.encode(passwd.encode(), 'hex')

salt_pass = bytearray.fromhex((salt_byte + passwd_byte).decode())

print(username + ":" + "SHA-256," + hashlib.sha256(salt_pass).hexdigest().upper() + "," + salt.upper() + ":")

参考链接:

  1. https://stackoverflow.com/que...
  2. http://blog.csdn.net/wjzhangc...

相关推荐