diff --git a/.sqlx/query-9a1d44d33c05841f52e56f57a0124d6ed4262f4c01ce9708aad88963e8b083b7.json b/.sqlx/query-8666ce4c33376a7949bc912ae2b4fbe58dd5206f5ac57f488ffe7f8a89e4239f.json similarity index 74% rename from .sqlx/query-9a1d44d33c05841f52e56f57a0124d6ed4262f4c01ce9708aad88963e8b083b7.json rename to .sqlx/query-8666ce4c33376a7949bc912ae2b4fbe58dd5206f5ac57f488ffe7f8a89e4239f.json index f5b0059..edb13d7 100644 --- a/.sqlx/query-9a1d44d33c05841f52e56f57a0124d6ed4262f4c01ce9708aad88963e8b083b7.json +++ b/.sqlx/query-8666ce4c33376a7949bc912ae2b4fbe58dd5206f5ac57f488ffe7f8a89e4239f.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n INSERT INTO users (\n pid,\n username,\n password,\n birthdate,\n timezone,\n email,\n country,\n language,\n marketing_allowed,\n off_device_allowed,\n region,\n gender,\n mii_data,\n verification_code,\n account_level\n ) VALUES (\n $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15\n )\n ", + "query": "\n INSERT INTO users (\n pid,\n username,\n password,\n birthdate,\n timezone,\n email,\n country,\n language,\n marketing_allowed,\n off_device_allowed,\n region,\n gender,\n mii_data,\n verification_code,\n account_level,\n nex_password\n ) VALUES (\n $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16\n )\n ", "describe": { "columns": [], "parameters": { @@ -19,10 +19,11 @@ "Bpchar", "Varchar", "Int4", - "Int4" + "Int4", + "Varchar" ] }, "nullable": [] }, - "hash": "9a1d44d33c05841f52e56f57a0124d6ed4262f4c01ce9708aad88963e8b083b7" + "hash": "8666ce4c33376a7949bc912ae2b4fbe58dd5206f5ac57f488ffe7f8a89e4239f" } diff --git a/src/account/account.rs b/src/account/account.rs index 5949761..1640cad 100644 --- a/src/account/account.rs +++ b/src/account/account.rs @@ -15,6 +15,7 @@ use sha2::{Digest, Sha256}; use crate::error::{Error, Errors}; use crate::nnid::oauth::TokenData; use crate::Pool; +use rand::Rng; macro_rules! request_try { ($expression:expr) => { @@ -173,7 +174,25 @@ pub async fn read_bearer_auth_token(connection: &Pool, token: &str) -> Option String { + let mut rng = rand::thread_rng(); + let mut output = String::with_capacity(16); + while output.len() < 16 { + let offset: u8 = rng.gen_range(0..62); + + let character = if offset < 10 { + (offset + b'0') as char + } else if offset < 36 { + (offset + 55) as char + } else { + (offset + 61) as char + }; + + output.push(character); + } + output +} pub struct Auth(pub User); @@ -235,10 +254,10 @@ impl<'r, const FORCE_BEARER_AUTH: bool> FromRequest<'r> for Auth16}", user.nex_password), - ..user - }; + // let user = User{ + // nex_password: format!("{:a>16}", user.nex_password), + // ..user + // }; Outcome::Success(Self(user)) } diff --git a/src/graphql/mod.rs b/src/graphql/mod.rs index c0d139d..ae5db30 100644 --- a/src/graphql/mod.rs +++ b/src/graphql/mod.rs @@ -127,7 +127,7 @@ impl Query { } }; - let nex_password = format!("{:a>16}",user.nex_password); + let nex_password = user.nex_password; Some(UserInfo { username: user.username, @@ -151,7 +151,7 @@ impl Query { .await .ok()?; - let nex_password = format!("{:a>16}",user.nex_password); + let nex_password = user.nex_password; Some(UserInfo { username: user.username, @@ -175,7 +175,7 @@ impl Query { .await .ok()?; - let nex_password = format!("{:a>16}",user.nex_password); + let nex_password = user.nex_password; Some(UserInfoWithPId { username: user.username, diff --git a/src/grpc/mod.rs b/src/grpc/mod.rs index 9ba4a34..992fcb9 100644 --- a/src/grpc/mod.rs +++ b/src/grpc/mod.rs @@ -77,9 +77,9 @@ impl grpc::account_server::Account for AccountService { .map_err(|_| Status::invalid_argument("No NEX account found"))? .nex_password; - let password_padded = format!("{:a>16}", password); + // let password_padded = format!("{:a>16}", password); - Ok(Response::new(GetNexPasswordResponse { password: password_padded })) + Ok(Response::new(GetNexPasswordResponse { password })) } async fn update_pnid_permissions( &self, diff --git a/src/nnid/people.rs b/src/nnid/people.rs index 461f7b0..ab2c4c6 100644 --- a/src/nnid/people.rs +++ b/src/nnid/people.rs @@ -1,11 +1,8 @@ -use std::env; -use std::io::Write; use chrono::{NaiveDate, NaiveDateTime}; use gxhash::{gxhash32, gxhash64}; -use once_cell::sync::Lazy; use rocket::{get, post, put, State}; use rocket::serde::{Deserialize, Serialize}; -use crate::account::account::{generate_password, Auth, User}; +use crate::account::account::{Auth, User, generate_nex_password, generate_password}; use crate::dsresponse::Ds; use crate::error::{Error, Errors}; use crate::nnid::pid_distribution::next_pid; @@ -14,8 +11,8 @@ use crate::Pool; use crate::xml::{Xml, YesNoVal}; use crate::email::send_verification_email; use rand::Rng; -use mii::{get_image_png, get_image_tga}; -use std::sync::Arc; +// Not in use currently. +//use mii::{get_image_png, get_image_tga}; use crate::mii_util::get_mii_img_url; const DATABASE_ERROR: Errors = Errors{ @@ -152,6 +149,7 @@ pub async fn create_account(database: &State, data: Xml, data: Xml, data: Xml