inejge / ldap3

A pure-Rust LDAP library using the Tokio stack
Apache License 2.0
226 stars 39 forks source link

about how change user password #131

Closed cn-hew closed 2 months ago

cn-hew commented 3 months ago

Hi, How should I change the user's password? I haven't seen any corresponding examples. My existing code can refer to #130 Thanks for any reply.

inejge commented 3 months ago

FYI: I'll be mostly offline for the next ten days or so, and I won't be able to handle any issues.

inejge commented 2 months ago

How should I change the user's password? I haven't seen any corresponding examples.

It depends on the server you're talking to and the configuration of the whole environment. Because of that, I consider this a usage question, and not a documentation issue. So, what type of server is it, in case I'm familiar with it?

cn-hew commented 2 months ago

Hi, thanks for your reply, I have solved my problem, the code is as follows

pub async fn modify_user_password(&mut self,dn:String,password:String) -> Result<LdapResult> {
        let attr_name = String::from("unicodePwd").into_bytes();
        let values: Vec<u8> = format!("\"{}\"",password).encode_utf16().flat_map(|v|v.to_le_bytes()).collect();
        let mut passwd = HashSet::new();
        passwd.insert(values);
        let mods = vec![
            Mod::Replace(attr_name,passwd)
        ];
        let result = self.ldap.modify(&dn, mods).await.unwrap();
        return Ok(result)
    }