1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#[derive(Debug, Clone)]
pub struct MultiFactorAuth {
    pub user: String,
    pub factor_token: String,
    pub token_expiration: u64,
}

impl MultiFactorAuth {
    pub fn new(user: &str, factor_token: &str, token_expiration: u64) -> Self {
        MultiFactorAuth {
            user: user.to_string(),
            factor_token: factor_token.to_string(),
            token_expiration,
        }
    }

    pub fn verify_token(&self, token: &str) -> bool {
        std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() < self.token_expiration && self.factor_token == token
    }
}