libreauth 0.18.1

Collection of user authentication tools.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::pass::LengthCalculationMethod;
use std::io::Cursor;
use unicode_reader::{CodePoints, Graphemes};

pub(crate) fn password_length(password: &str, method: LengthCalculationMethod) -> usize {
	match method {
		LengthCalculationMethod::Bytes => password.len(),
		LengthCalculationMethod::Characters => {
			let mut len = 0;
			for _ in password.chars() {
				len += 1;
			}
			len
		}
		LengthCalculationMethod::CodePoints => CodePoints::from(Cursor::new(password)).count(),
		LengthCalculationMethod::Graphemes => Graphemes::from(Cursor::new(password)).count(),
	}
}