import hashlib, uuid
salt = uuid.uuid4().hex
hashed_password = hashlib.sha512(password + salt).hexdigest()
#!/usr/bin/python3
import hashlib, uuid
SEPARATOR = "&"
# generate hash string with salt
def gen_hash(pwd, salt):
return hashlib.sha512(pwd + salt).hexdigest()
# generage hash password string (for safe to file)
def gen_pw_string(pwd):
salt = uuid.uuid4().hex
return salt + SEPARATOR + gen_hash(pwd, salt)
# parse hash password string, split it by salt and password hash
def parse_pw_string(pwstring):
return pwstring.split(SEPARATOR)
# check password by its password hash string
def check_pwd(pwd, pwstring):
salt, _pwhash = parse_pw_string(pwstring)
pwhash = gen_hash(pwd, salt)
return pwhash == _pwhash
### test time!
pwd1 = "123456"
pwd2 = "qwerty"
# genetate hash strings (may be saved to file or DB)
pwstring1 = gen_pw_string(pwd1)
pwstring2 = gen_pw_string(pwd2)
print(pwd1, pwstring1)
print(pwd2, pwstring2)
# check passwords
# must be True
print(check_pwd(pwd1, pwstring1))
print(check_pwd(pwd2, pwstring2))
# must be False
print(check_pwd(pwd1, pwstring2))
print(check_pwd(pwd2, pwstring1))
('123456', 'f2b56ad9006a475e8c4f9b64446c3f5b&46c2d252a2667cc4b5a754ef5816e981570fd4bd9ced3ed1a6f6aaeae8ae83b795d6ffb66b3fe34650469b1c0d537785c2611157d41ebee6e54dc09527600a0c')
('qwerty', 'f2b56ad9006a475e8c4f9b64446c3f5b&3da9c4223c9fa2c66f5d70432401db14a89ddfe6feb99423083d152f98ef199d484b95b09a6535c766f28223c422cd1d862250867c12c7077144564b5c3fbc79')
True
True
False
False
long startTime = System.nanoTime();
methodToTime();
long endTime = System.nanoTime();
long duration = (endTime - startTime);
Instant start = Instant.now();
Thread.sleep(63553);
Instant end = Instant.now();
System.out.println(Duration.between(start, end)); // prints PT1M3.553S
truncate -s 500M my-file-system.img
- создать файликmkfs.ext4 my-file-system.img
- создать файловую систему на немmount -o loop my-file-system.img /mnt
- подмонтироватьdf -h /mnt
- проверить размерчикumount /mnt
- отмонтироватьroot@leah-pc /h/leah# truncate -s 500M my-file-system.img
root@leah-pc /h/leah# mkfs.ext4 my-file-system.img
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done
Creating filesystem with 128000 4k blocks and 128000 inodes
Filesystem UUID: ada9f825-92d5-4410-b186-eda1ef2edfeb
Superblock backups stored on blocks:
32768, 98304
Allocating group tables: done
Сохранение таблицы inod'ов: done
Создание журнала (4096 блоков): готово
Writing superblocks and filesystem accounting information: готово
root@leah-pc /h/leah# mount -o loop /home/leah/my-file-system.img /mnt
root@leah-pc /h/leah# df -h /mnt
Файл.система Размер Использовано Дост Использовано% Cмонтировано в
/dev/loop26 469M 768K 433M 1% /mnt
root@leah-pc /h/leah# umount /mnt
Arraylist points = new Arraylist();
points.add(p1);
..
points.add(p2);
Iterator<String> iter = points.iterator();
while(iter.hasNext()){
Point p = iter.next());
iter.remove();
if(points.contains(p)) return true; // здесь определяем, что точка равна еще какой-то точке.
}