int main(int argc, char *argv[]){ char oldpss[30]; char newpss[30]; char msg[20]; strcpy(msg,"Old password: "******"New password: "******"Usage: passwd program needs a user in the first argument\n"); exit(); } if(user_exist(argv[1])){ while(getcmd(oldpss, sizeof(oldpss),msg) >= 0){ break; } oldpss[strlen(oldpss)-1]='\0'; while(getcmd(newpss, sizeof(newpss),msg1) >= 0){ break; } newpss[strlen(newpss)-1]='\0'; changepasswd( argv[1],oldpss,newpss); } exit(); }
/** * \brief Filters the directory entry due to -user parameter. * * Applies -user filter (if defined) to file_info. * * \param current_param currently processed parameter index. * \param params Program parameter arguments given by user. * \param file_info as read from operating system. * * \return boolean result indicating filter has matched. * \retval TRUE name filter matched or not given. * \retval FALSE no match found. */ static boolean filter_user(const int current_param, const char* const* params, StatType* file_info) { unsigned int search_uid = 0; char * end_ptr = NULL; struct passwd* pwd = NULL; search_uid = strtol(params[current_param + 1], &end_ptr, USERID_BASE); if (('\0' != *end_ptr) || user_exist(params[current_param + 1], FALSE)) { /* string to int conversion failed --> we have a username */ /* or special case --> username is pure numeric */ if (user_exist(params[current_param + 1], FALSE)) { pwd = getpwuid(file_info->st_uid); if (pwd != NULL) { if (strcmp(pwd->pw_name, params[current_param + 1]) == 0) { /* parameter of -user is equal to * user name derived from UID */ return TRUE; } } return FALSE; } else { snprintf(get_print_buffer(), MAX_PRINT_BUFFER, "`%s' is not the name of a known user", params[current_param + 1]); print_error(get_print_buffer()); cleanup(TRUE); return FALSE; } } else { /* successfull string to int conversion */ /* -> parameter of -user seems to be an UID */ return (search_uid == file_info->st_uid); } return TRUE; }
void Register::add_user(QString a,QString b) { QFile f("..\\quesion\\user\\user.txt"); if(!f.open(QIODevice::WriteOnly|QIODevice::Append)) { qDebug()<< "no vertification file!"; } QTextStream out(&f); if(user_exist(a)){ warning war("用户名已被注册!"); war.show(); war.exec(); this->close(); } out << a << endl << b << endl; f.close(); warning* war = new warning("注册成功!",this); war->show(); war->exec(); this->close(); }