Hi, I seem to be getting a use of moved value error on info.username in database::hset. How do I fix this? I have no issues in using info.username in the database::hget method. Thanks in advance.
#[derive(Deserialize)]
struct LogIn
{
username: String,
password: String
}
async fn authentication(info: web::Json<LogIn>) -> impl Responder
{
let info = info.into_inner();
if info.password == database::hget("users".to_string(), info.username).ok().unwrap()
{
let credentials: u32 = rand::thread_rng().gen();
database::hset("sessions".to_string(), credentials.to_string(), info.username).ok();
HttpResponse::Ok().body(credentials.to_string())
}
else
{
HttpResponse::Ok().body("Failed to log in!")
}
}
You can use info.username.clone() instead of info.username for the hset call. If that doesn't fix it, please give more context about the definitions of web::Json, LogIn, database::hget and database::hset.
It's off topic, but the OP example should not go into any kind of production environment.
At the very least the client should hash the password with a cryptographically secure hashing algorithm before it's sent over the wire. This prevents plaintext passwords from being sent over the (potentially unencrypted) connection.
Server side other things should happen too, e.g. salting the hash and rehashing it.