Getting a "Use of Moved Value" error (Actix Deserialization)

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.

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("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.

Doesn't seem to work, I added the json deserialization code does that help?

What is the error when using clone?

Borrow of moved value; value borrowed here after move

Ah, the clone should be for the hget call not the hset call. My bad.

It works! Thank you for your help!

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.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.