简体   繁体   中英

popen password change linux

I try to change the password for an user on a linux system. I opened a pipe for this. Works great, except the user enters passwords that are treated as "weak" (I handle the case that the password is to short). On the terminal this prints a warning and then you have to re-enter the password to verify.

Here are the few lines of code (i stripped all the parts that are not relevant).

fp = popen("passwd myuser", "w");
fprintf(fp, "%s\n", newPw);
fprintf(fp, "%s\n", newPw);
status = pclose(fp);

How can I handle the new case, or is there a more elegant way to deal with password changes I am not aware of?

just added another fprintf(fp, "%s\\n", newPw) to handle the additional verification. If everything runs fine and the password is accepted as is, the additional print in the pipe is no problem...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM