pub fn auth_user(
        &self,
        user: &str,
        password: impl AsRef<[u8]>,
        _client_addr: &str,
    ) -> Result<bool> {
        let user = self.get_user(user)?;

        match user.auth_type {
            AuthType::None => Ok(true),
            AuthType::PlainText => Ok(user.password == password.as_ref()),
            // MySQL already did x = sha1(x)
            // so we just check double sha1(x)
            AuthType::DoubleSha1 => {
                let mut m = sha1::Sha1::new();
                m.update(password.as_ref());

                let bs = m.digest().bytes();
                let mut m = sha1::Sha1::new();
                m.update(&bs[..]);

                Ok(user.password == m.digest().bytes().to_vec())
            }
            AuthType::Sha256 => {
                let result = sha2::Sha256::digest(password.as_ref());
                Ok(user.password == result.to_vec())
            }
        }
    }
// Auth the user and password for different Auth type.
Auth the user and password for different Auth type.
Auth the user and password for different Auth type .
pub fn auth_user(
        &self,
        user: &str,
        password: impl AsRef<[u8]>,
        _client_addr: &str,
    ) -> Result<bool> {
        let user = self.get_user(user)?;
        match user.auth_type {
            AuthType::None => Ok(true),
            AuthType::PlainText => Ok(user.password == password.as_ref()),
            // MySQL already did x = sha1(x)
            // so we just check double sha1(x)
            AuthType::DoubleSha1 => {
                let mut m = sha1::Sha1::new();
                m.update(password.as_ref());
                let bs = m.digest().bytes();
                let mut m = sha1::Sha1::new();
                m.update(&bs[..]);
                Ok(user.password == m.digest().bytes().to_vec())
            }
            AuthType::Sha256 => {
                let result = sha2::Sha256::digest(password.as_ref());
                Ok(user.password == result.to_vec())
            }
        }
    }
pub fn auth_user ( & self , user : & str , password : impl AsRef < [ u8 ] > , _client_addr : & str , ) -> Result < bool > { let user = self . get_user ( user ) ? ; match user . auth_type { AuthType :: None => Ok ( true ) , AuthType :: PlainText => Ok ( user . password == password . as_ref ( ) ) , // MySQL already did x = sha1(x) // so we just check double sha1(x) AuthType :: DoubleSha1 => { let mut m = sha1 :: Sha1 :: new ( ) ; m . update ( password . as_ref ( ) ) ; let bs = m . digest ( ) . bytes ( ) ; let mut m = sha1 :: Sha1 :: new ( ) ; m . update ( & bs [ .. ] ) ; Ok ( user . password == m . digest ( ) . bytes ( ) . to_vec ( ) ) } AuthType :: Sha256 => { let result = sha2 :: Sha256 :: digest ( password . as_ref ( ) ) ; Ok ( user . password == result . to_vec ( ) ) } } }
Auth the user and password for different Auth type.
Auth the user and password for different Auth type .
&self
user
&str
password
impl AsRef<[u8]>
_client_addr
&str
&self
user
&str
password
impl AsRef<[u8]>
_client_addr
&str