ajout des fichiers du projet TheNewJoplin

This commit is contained in:
2022-11-10 15:55:58 -05:00
parent 88f05c5529
commit 45a6522e2f
9 changed files with 924 additions and 31 deletions
View File
+56
View File
@@ -0,0 +1,56 @@
# --==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-- #
# Bruno Charest
# 2022-08-09
#
# __ DESCRIPTIONS __
# password_utils : procedure related password
#
# Inspiration of : https://ttj.dk/blog/2019/01/20/setup-a-website-with-nim
# Copyright 2019 - Thomas T. Jarløv
# --==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-- #
import md5
import bcrypt
import random
randomize()
# --==--==--==--==--==--==--==--==--==--==-- #
# Let and VAR : for random
# --==--==--==--==--==--==--==--==--==--==-- #
var urandom: File
let useUrandom = urandom.open("/dev/urandom")
# --==--==--==--==--==--==--==--==--==--==--=--==--==--=--==--==--=--==--==-- #
# PROC : Make Salt
## : Generate random salt. Uses cryptographically secure /dev/urandom
## : on platforms where it is available, and Nim's random module in other cases.
# --==--==--==--==--==--==--==--==--==--==--=--==--==--=--==--==--=--==--==-- #
proc makeSalt*(): string =
result = ""
if useUrandom:
var randomBytes: array[0..127, char]
discard urandom.readBuffer(addr(randomBytes), 128)
for ch in randomBytes:
if ord(ch) in {32..126}:
result.add(ch)
else:
for i in 0..127:
result.add(chr(rand(94) + 32)) # Generate numbers from 32 to 94 + 32 = 126
# --==--==--==--==--==--==--==--==--==--==-- #
# PROC : Make session key
## Creates a random key to be used to authorize a session.
# --==--==--==--==--==--==--==--==--==--==-- #
proc makeSessionKey*(): string =
let random = makeSalt()
return bcrypt.hash(random, genSalt(8))
# --==--==--==--==--==--==--==--==--==--==-- #
# PROC : make password
## Creates an MD5 hash by combining password and salt
# --==--==--==--==--==--==--==--==--==--==-- #
proc makePassword*(password, salt: string, comparingTo = ""): string =
let bcryptSalt = if comparingTo != "": comparingTo else: genSalt(8)
result = hash(getMD5(salt & getMD5(password)), bcryptSalt)
+22
View File
@@ -0,0 +1,22 @@
# --==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-- #
# Bruno Charest
# 2022-10-25
#
# __ DESCRIPTIONS __
# utils : procedures generals utils
#
# --==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-- #
import std/times
# --==--==--==--==--==--==--==--==--==--==--==--==--==--==-- #
# PROC : Convert epoch millisecond time to human readable time
# --==--==--==--==--==--==--==--==--==--==--==--==--==--==-- #
proc convertEpochToHumanTime*(epochTime: int): string =
var humanTime: Time
var dateTime: string
humanTime = fromUnix(convert(Milliseconds, Seconds, epochTime))
dateTime = format(humanTime, "yyyy-MM-dd' 'HH:mm")
# echo dateTime
return dateTime