static bool CheckMenuPassword(const string& original_password) { const string expected_password = (original_password == "*SYSTEM") ? syscfg.systempw : original_password; bout.nl(); string actual_password = input_password("|#2SY: ", 20); return actual_password == expected_password; }
/*********************************************************************** module : [菜单操作] function : [设置管理员密码] return : [无] comment : [全局普通函数] machine : [EH-0818] language : [CHN] keyword : [MENU] date : [11/08/02] author : [chen-zhengkai] ************************************************************************/ void setAdmPsd_task() { GETSTR_PARAM gs; char cueStr[30] = "请输入新管理员密码"; char remwrds[] = "(6-8位):"; char dspBuf[30] = {0}; const char retStr[] = "按任意键返回"; char admPsd[9] = {0}; char psdtmp[9] = {0}; char ret = 1; if ( !adminPassword(1) ) { //输入旧的管理员密码验证 DispStr_CE(0, 0, cueStr, DISP_POSITION|DISP_CLRSCR); if (input_password(remwrds, psdtmp) ) { strcpy(dspBuf, "输入失败"); ret = 0; } if (ret) { strcpy(cueStr, "请再次输入密码"); DispStr_CE(0, 0, cueStr, DISP_POSITION|DISP_CLRSCR); if ( input_password(remwrds ,admPsd) ) { strcpy(dspBuf, "输入失败"); ret = 0; } } if (ret && strncmp(admPsd, psdtmp, 8) ) { //两次输入不一致 strcpy(dspBuf, "两次输入不一致"); ret = 0; } if (ret && eeprom_write(admPsd, sizeof(admPsd), EEPROM_OFFSET_ADM_PSD)) { strcpy(dspBuf, "EEPROM读写失败"); ret = 0; } if (ret) { strcpy(dspBuf, "密码设置成功"); } DispStr_CE(0, 6, dspBuf, DISP_CENTER|DISP_CLRSCR); DispStr_CE(0, 10, retStr, DISP_CENTER); delay_and_wait_key( 3, EXIT_KEY_ALL, 0 ); } }
/** * Queries user and verifies system password. * @return true if the password entered is valid. */ bool ValidateSysopPassword() { GetSession()->bout.NewLine(); if (so()) { if (incom) { std::string password; input_password("|#7SY: ", password, 20); if (password == syscfg.systempw) { return true; } } else if (AllowLocalSysop()) { return true; } } return false; }
/*********************************************************************** module : [机器设置操作] function : [管理员密码验证] return : [0: 密码匹配成功 -1: 密码匹配不成功 -2: 没有正确输入 -3: eeprom读写失败] comment : [全局普通函数] machine : [EH-0818] language : [CHN] keyword : [MAC_SET] date : [11/08/02] author : [chen-zhengkai] ************************************************************************/ char adminPassword(int type) { // GETSTR_PARAM gs; char cueStr[30] = {0}; char remwrds[] = "(6-8位):"; const char retStr[] = "按任意键返回"; char admPsd[9] = {0}; //输入的密码 char admPsd_t[9] = {0}; //内存里的密码 if (type == 0) { strcpy(cueStr, "请输入管理员密码"); } else { strcpy(cueStr, "请输入旧管理员密码"); } DispStr_CE(0, 0, cueStr, DISP_POSITION|DISP_CLRSCR); if (input_password(remwrds, admPsd)) { DispStr_CE(0, 6, "输入失败", DISP_CENTER|DISP_CLRSCR); DispStr_CE(0, 10, retStr, DISP_CENTER); delay_and_wait_key( 3, EXIT_KEY_ALL, 0 ); return -2; } if (eeprom_read(admPsd_t, 9, EEPROM_OFFSET_ADM_PSD)) { DispStr_CE(0, 6, "EEPROM读写失败", DISP_CENTER|DISP_CLRSCR); DispStr_CE(0, 10, retStr, DISP_CENTER); delay_and_wait_key( 3, EXIT_KEY_ALL, 0 ); return -3; } if ( strncmp(admPsd_t, admPsd, 8) ) { DispStr_CE(0, 6, "密码不正确", DISP_CENTER|DISP_CLRSCR); DispStr_CE(0, 10, retStr, DISP_CENTER); delay_and_wait_key( 3, EXIT_KEY_ALL, 0 ); return -1; } return 0; }
void tool_init(gint* ac, gchar*** av, const gchar* tool_name, GOptionEntry* tool_entries) { GError *local_err = NULL; init(); opt_context = g_option_context_new(tool_name); if (tool_allow_unknown_options) g_option_context_set_ignore_unknown_options(opt_context, TRUE); if (tool_entries) g_option_context_add_main_entries(opt_context, tool_entries, NULL); g_option_context_add_main_entries(opt_context, auth_options, NULL); g_option_context_add_main_entries(opt_context, basic_options, NULL); if (!g_option_context_parse(opt_context, ac, av, &local_err)) { g_printerr("ERROR: Option parsing failed: %s\n", local_err->message); g_clear_error(&local_err); exit(1); } print_version(); // load username/password from ini file if (!opt_no_config || opt_config) { gboolean status; gc_key_file_unref GKeyFile* kf = g_key_file_new(); if (opt_config) status = g_key_file_load_from_file(kf, opt_config, 0, NULL); else { status = g_key_file_load_from_file(kf, MEGA_RC_FILENAME, 0, NULL); if (!status) { gc_free gchar* tmp = g_build_filename(g_get_home_dir(), MEGA_RC_FILENAME, NULL); status = g_key_file_load_from_file(kf, tmp, 0, NULL); } } if (status) { if (!opt_username) opt_username = g_key_file_get_string(kf, "Login", "Username", NULL); if(!opt_password) opt_password = g_key_file_get_string(kf, "Login", "Password", NULL); gint to = g_key_file_get_integer(kf, "Cache", "Timeout", &local_err); if (local_err == NULL) opt_cache_timout = to; else g_clear_error(&local_err); } } if (!opt_username) { g_printerr("ERROR: You must specify your mega.co.nz username (email)\n"); exit(1); } if (!opt_password && opt_no_ask_password) { g_printerr("ERROR: You must specify your mega.co.nz password\n"); exit(1); } if (!opt_password) opt_password = input_password(); }
int main() { uint8_t index; uint8_t menulen; uint8_t button_pressed = UINT8_MAX - 1; uint16_t i; uint8_t pass_len; //Since we are waiting indefinitely for input from keyboard, //the watchdog is not applicable anymore //wdt_enable(WDTO_1S); // enable 1s watchdog timer init(); for (i = 0; i < sizeof(keyboard_report); i++) // clear report initially ((uchar *) &keyboard_report)[i] = 0; usbDeviceDisconnect(); // enforce re-enumeration for (i = 0; i < 250; i++) { // wait 500 ms //wdt_reset(); _delay_ms(2); } usbDeviceConnect(); // Enable interrupts after re-enumeration sei(); //Enable this to reinitialize passwords/EEPROM //eeprom_write_byte(0,0); pass_no = read_passwords(&passwords); index = 0; mode = MODE_MENU; menulen = MENU_LENGTH; while (1) { //wdt_reset(); // keep the watchdog happy usbPoll(); //Only display stuff if a button was pressed //(most likely something changed on the screen) if (button_pressed != UINT8_MAX) { lcd_clrscr(); if (mode == MODE_MENU) { strcpy_P(stringBuffer, (PGM_P) pgm_read_word(&(menu_items[index]))); lcd_puts(stringBuffer); } else { lcd_puts(passwords[index]); } } button_pressed = poll_buttons(); switch (button_pressed) { case MENU: //Get back to the main menu mode = MODE_MENU; index = 0; menulen = MENU_LENGTH; toggle_led(PB0); break; case CYCLE: //Prepare next item for display if (index < menulen - 1) { lcd_clrscr(); index++; } else { index = 0; } toggle_led(PB0); break; case SELECT: if (mode == MODE_MENU) { //We can add password directly from the MENU mode (main menu) if (index == MODE_ADD) { uint8_t pass_len; pass_len = input_password(); if (pass_len > 0) { stringBuffer[pass_len] = '\0'; passwords = realloc(passwords, (pass_no + 1) * sizeof(char*)); passwords[pass_no] = malloc(pass_len * sizeof(char)); strcpy(passwords[pass_no], stringBuffer); pass_no++; menulen = pass_no; write_passwords(pass_no, passwords); } //Get back to the MENU mode (main menu) mode = MODE_MENU; menulen = MENU_LENGTH; toggle_led(PB0); } else { //Enter the corresponding mode mode = index; index = 0; menulen = pass_no; } } else { //in SEND, REMOVE or CHANGE mode if (index < menulen) { switch (mode) { case MODE_SEND: //Send password to the PC strcpy(stringBuffer, passwords[index]); messagePtr = 0; messageState = STATE_SEND; //Stay in the SEND mode displaying the same password break; case MODE_REMOVE: //Remove password free(passwords[index]); for (i = index; i < pass_no - 1; i++) { passwords[i] = passwords[i + 1]; } pass_no--; passwords = realloc(passwords, pass_no * sizeof(char*)); write_passwords(pass_no, passwords); //Stay in the REMOVE mode, but display the first password index = 0; menulen = pass_no; break; case MODE_CHANGE: pass_len = input_password(); if (pass_len > 0) { stringBuffer[pass_len] = '\0'; passwords[index] = realloc(passwords[index], pass_len); strcpy(passwords[index], stringBuffer); write_passwords(pass_no, passwords); } //Stay in the CHANGE mode, but display the first password index = 0; toggle_led(PB0); break; } } } break; } // characters are sent when messageState == STATE_SEND if (usbInterruptIsReady() && messageState == STATE_SEND) { messageState = buildReport(); usbSetInterrupt((void *) &keyboard_report, sizeof(keyboard_report)); } } return 0; }