Merge branch 'nexpwd' into 'main'
Add functionality for generating random NEX passwords See merge request spfn/account!3
This commit is contained in:
commit
400ab9a348
5 changed files with 41 additions and 21 deletions
|
|
@ -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"
|
||||
}
|
||||
|
|
@ -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<Us
|
|||
Some(user)
|
||||
}
|
||||
|
||||
pub fn generate_nex_password() -> 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<const FORCE_BEARER_AUTH: bool>(pub User);
|
||||
|
||||
|
|
@ -235,10 +254,10 @@ impl<'r, const FORCE_BEARER_AUTH: bool> FromRequest<'r> for Auth<FORCE_BEARER_AU
|
|||
return Outcome::Error((Status::BadRequest, INVALID_TOKEN_ERRORS));
|
||||
}
|
||||
|
||||
let user = User{
|
||||
nex_password: format!("{:a>16}", user.nex_password),
|
||||
..user
|
||||
};
|
||||
// let user = User{
|
||||
// nex_password: format!("{:a>16}", user.nex_password),
|
||||
// ..user
|
||||
// };
|
||||
|
||||
Outcome::Success(Self(user))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<Pool>, data: Xml<AccountCreationDat
|
|||
|
||||
|
||||
let password = generate_password(pid, &password).ok_or(None)?;
|
||||
let nex_password = generate_nex_password();
|
||||
|
||||
sqlx::query!("
|
||||
INSERT INTO users (
|
||||
|
|
@ -169,9 +167,10 @@ pub async fn create_account(database: &State<Pool>, data: Xml<AccountCreationDat
|
|||
gender,
|
||||
mii_data,
|
||||
verification_code,
|
||||
account_level
|
||||
account_level,
|
||||
nex_password
|
||||
) VALUES (
|
||||
$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15
|
||||
$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16
|
||||
)
|
||||
",
|
||||
pid,
|
||||
|
|
@ -188,7 +187,8 @@ pub async fn create_account(database: &State<Pool>, data: Xml<AccountCreationDat
|
|||
gender.as_ref(),
|
||||
data.as_ref(),
|
||||
verification_code,
|
||||
account_level
|
||||
account_level,
|
||||
nex_password
|
||||
).execute(database).await.unwrap();
|
||||
|
||||
//generate_s3_images(pid, &data).await;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue