mirror of
https://github.com/janeczku/calibre-web
synced 2025-10-12 14:17:40 +00:00
new random password generation algorithm to ensure compliance with password rules
bugfix opds login limit
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import random
|
||||
import io
|
||||
import mimetypes
|
||||
import re
|
||||
@@ -621,11 +622,35 @@ def reset_password(user_id):
|
||||
ub.session.rollback()
|
||||
return 0, None
|
||||
|
||||
|
||||
def generate_random_password(min_length):
|
||||
min_length = max(8, min_length) - 4
|
||||
random_source = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%&*()?"
|
||||
# select 1 lowercase
|
||||
s = "abcdefghijklmnopqrstuvwxyz"
|
||||
password = [s[c % len(s)] for c in os.urandom(1)]
|
||||
# select 1 uppercase
|
||||
s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
password.extend([s[c % len(s)] for c in os.urandom(1)])
|
||||
# select 1 digit
|
||||
s = "01234567890"
|
||||
password.extend([s[c % len(s)] for c in os.urandom(1)])
|
||||
# select 1 special symbol
|
||||
s = "!@#$%&*()?"
|
||||
password.extend([s[c % len(s)] for c in os.urandom(1)])
|
||||
|
||||
# generate other characters
|
||||
password.extend([random_source[c % len(random_source)] for c in os.urandom(min_length)])
|
||||
|
||||
# password_list = list(password)
|
||||
# shuffle all characters
|
||||
random.SystemRandom().shuffle(password)
|
||||
return ''.join(password)
|
||||
|
||||
|
||||
'''def generate_random_password(min_length):
|
||||
s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%&*()?"
|
||||
passlen = min_length
|
||||
return "".join(s[c % len(s)] for c in os.urandom(passlen))
|
||||
return "".join(s[c % len(s)] for c in os.urandom(passlen))'''
|
||||
|
||||
|
||||
def uniq(inpt):
|
||||
|
Reference in New Issue
Block a user