initial commit
This commit is contained in:
commit
7c6485d459
5
.env
Normal file
5
.env
Normal file
@ -0,0 +1,5 @@
|
||||
# Postgres
|
||||
# DATABASE_URL=postgres://postgres@localhost/my_database
|
||||
# SQLite
|
||||
DATABASE_URL=sqlite:brass.db
|
||||
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target
|
||||
*.db
|
2149
Cargo.lock
generated
Normal file
2149
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
13
Cargo.toml
Normal file
13
Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "brass"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
sqlx = { version = "0.6", features = [ "runtime-async-std-rustls" ] }
|
||||
actix-web = { version = "4" }
|
||||
askama = "0.12.0"
|
||||
serde = { version = "1.0.164", features = [ "derive"]}
|
||||
argon2 = "0.5.0"
|
6
migrations/20230609121618_initial.sql
Normal file
6
migrations/20230609121618_initial.sql
Normal file
@ -0,0 +1,6 @@
|
||||
CREATE TABLE IF NOT EXISTS users
|
||||
(
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
password TEXT NOT NULL
|
||||
);
|
4
src/auth/mod.rs
Normal file
4
src/auth/mod.rs
Normal file
@ -0,0 +1,4 @@
|
||||
pub mod routes;
|
||||
mod utils;
|
||||
|
||||
pub use routes::init;
|
41
src/auth/routes.rs
Normal file
41
src/auth/routes.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use actix_web::{Responder, web, HttpResponse};
|
||||
use askama::Template;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::auth::utils::hash_plain_password;
|
||||
|
||||
pub fn init(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(get_login);
|
||||
cfg.service(post_login);
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct LoginForm {
|
||||
name: String,
|
||||
password: String
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "login.html")]
|
||||
struct LoginTemplate {
|
||||
}
|
||||
|
||||
|
||||
#[actix_web::get("/login")]
|
||||
async fn get_login() -> impl Responder {
|
||||
let bla = LoginTemplate {};
|
||||
|
||||
HttpResponse::Ok()
|
||||
.body(bla.render().unwrap())
|
||||
}
|
||||
|
||||
#[actix_web::post("/login")]
|
||||
async fn post_login(web::Form(form): web::Form<LoginForm>) -> impl Responder {
|
||||
println!("{} - {}", form.name, form.password);
|
||||
|
||||
let hash = hash_plain_password(&form.password);
|
||||
|
||||
println!("{hash}");
|
||||
|
||||
"dfgdg"
|
||||
}
|
20
src/auth/utils.rs
Normal file
20
src/auth/utils.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use argon2::{
|
||||
password_hash::{rand_core::OsRng, PasswordHash, PasswordHasher, SaltString},
|
||||
Argon2,
|
||||
};
|
||||
|
||||
pub fn hash_plain_password(plain: &str) -> String {
|
||||
let salt = SaltString::generate(&mut OsRng);
|
||||
|
||||
// Argon2 with default params (Argon2id v19)
|
||||
Argon2::default()
|
||||
.hash_password(plain.as_bytes(), &salt)
|
||||
.unwrap()
|
||||
.to_string()
|
||||
|
||||
// Verify password against PHC string.
|
||||
//
|
||||
// NOTE: hash params from `parsed_hash` are used instead of what is configured in the
|
||||
// `Argon2` instance.
|
||||
// PasswordHash::new(&password_hash).unwrap().to_string()
|
||||
}
|
23
src/main.rs
Normal file
23
src/main.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use actix_web::{web, App, HttpServer, Responder};
|
||||
|
||||
mod auth;
|
||||
|
||||
async fn index() -> impl Responder {
|
||||
"Hello world!"
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new().service(
|
||||
// prefixes all resources and routes attached to it...
|
||||
web::scope("/app")
|
||||
// ...so this handles requests for `GET /app/index.html`
|
||||
.route("/index.html", web::get().to(index)),
|
||||
)
|
||||
.configure(auth::init)
|
||||
})
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
18
templates/login.html
Normal file
18
templates/login.html
Normal file
@ -0,0 +1,18 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Brass - Login</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Brass - Anmeldung</h1>
|
||||
<p>Gib dein Nutzernamen und das Passwort ein:</p>
|
||||
<form>
|
||||
<label for="name">Nutzername:</label>
|
||||
<input name="name" type="text">
|
||||
|
||||
<label for="password">Passwort:</label>
|
||||
<input name="password" type="password">
|
||||
|
||||
<input type="submit" formmethod="post">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user