Update rand and sha

This commit is contained in:
red binder 2026-04-29 10:42:09 +02:00
commit 8940b099e9
4 changed files with 42 additions and 13 deletions

View file

@ -20,7 +20,7 @@ use openssl::ecdsa::EcdsaSig;
use openssl::error::ErrorStack;
use openssl::nid::Nid;
use openssl::pkey::Public;
use rand::Rng;
use rand::prelude::*;
use rocket::http::Status;
use rocket::request::{FromRequest, Outcome};
use rocket::{Request, async_trait};
@ -81,9 +81,9 @@ pub struct _CertificatePid {
fn generate_nintendo_hash(pid: i32, text_password: &str) -> String {
let mut sha = Sha256::new();
sha.write_all(&bytes_of(&pid)).unwrap();
sha.write_all(&[0x02, 0x65, 0x43, 0x46]).unwrap();
sha.write_all(text_password.as_bytes()).unwrap();
sha.update(&bytes_of(&pid));
sha.update(&[0x02, 0x65, 0x43, 0x46]);
sha.update(text_password.as_bytes());
hex::encode(&sha.finalize()[..])
}
@ -193,18 +193,18 @@ pub async fn read_bearer_auth_token(connection: &Pool, token: &str) -> Option<Us
}
pub fn generate_nex_password() -> String {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let mut output = String::with_capacity(16);
while output.len() < 16 {
let offset: u8 = rng.gen_range(0..62);
let offset: u8 = rng.random_range(0..62);
let character = if offset < 10 {
(offset + b'0') as char
} else if offset < 36 {
(offset + 55) as char
(offset + 55) as char // A-Z
} else {
(offset + 61) as char
(offset + 61) as char // a-z
};
output.push(character);

View file

@ -11,7 +11,7 @@ use crate::nnid::timezones::{OFFSET_FROM_TIMEZONE};
use crate::Pool;
use crate::xml::{Xml, YesNoVal};
use crate::email::send_verification_email;
use rand::Rng;
use rand::prelude::*;
// Not in use currently.
//use mii::{get_image_png, get_image_tga};
use crate::mii_util::get_mii_img_url;
@ -118,7 +118,7 @@ pub async fn create_account(database: &State<Pool>, data: Xml<AccountCreationDat
let pid = next_pid(database).await;
let verification_code: i32 = rand::thread_rng().gen_range(100_000..1_000_000);
let verification_code: i32 = rand::rng().random_range(100_000..1_000_000);
let AccountCreationData {
user_id,