| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 619 人关注过本帖
标题:二次的密码验证机制
取消只看楼主 加入收藏
ianlin1024
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2023-3-11
结帖率:100%
收藏
已结贴  问题点数:18 回复次数:0 
二次的密码验证机制
又来发第二次帖了,这次遇到的问题是临时想到的
我想在原有程式的基础下再添加一个二次输入验证的机制(就有点像在注册帐号时的"请再输入一次密码"的感觉)
但因为我在先前有写一段纪录按键延迟的阵列,想把延迟也当作验证的一部份

大致流程
1.照"节奏"第一次输入密码时:显示输入的数(矩阵记录下密码与间隔时间),按下回车跳至第二次的验证
2.第二次验证密码:第二次验证需重复第一次的密码与节奏(考虑到人的节奏感,希望在第一次的节奏基础上有+-的容错时间差)
3.如果符合则跳至 Keys pressed/ intervals between key presses那一段,如不符合需再重复输入(希望至多5次)

麻烦各位老师了!

程式碼如下:
程序代码:
#include <stdio.h>
#include <windows.h>

#define MAX_KEYS 50
#define MAX_INTERVALS (MAX_KEYS - 1) 

int main()
{
    INPUT_RECORD input_record;
    HANDLE console = GetStdHandle(STD_INPUT_HANDLE);
    DWORD events_read; 
    LARGE_INTEGER start_time, end_time, frequency;
    BOOL last_event_was_release = FALSE;
    LARGE_INTEGER last_release_time;
    int key_count = 0;
    char keys[MAX_KEYS] = {0};
    char password[50];
    char verify_password[50];
    double intervals[MAX_INTERVALS - 1] = {0}; 
    
    QueryPerformanceFrequency(&frequency);

    
    printf("請設定節拍密碼\n\n");
    while (1) {
        
    
        if (ReadConsoleInput(console, &input_record, 1, &events_read)) {
            if (input_record.EventType == KEY_EVENT) {
                if (input_record.Event.KeyEvent.bKeyDown) {
                    if (last_event_was_release && input_record.Event.KeyEvent.wVirtualKeyCode != VK_RETURN) {
                        LARGE_INTEGER press_time;
                        QueryPerformanceCounter(&press_time);
                        double interval = (double)(press_time.QuadPart - last_release_time.QuadPart) / frequency.QuadPart * 1.0;
                        intervals[key_count - 1] = interval;
                        printf("Time since last release: %.3fs\n", (double)(press_time.QuadPart - last_release_time.QuadPart) / frequency.QuadPart * 1.0);
                    }
                    QueryPerformanceCounter(&start_time);
                    last_event_was_release = FALSE;
                     
                    if (key_count < MAX_KEYS) {
                        keys[key_count++] = input_record.Event.KeyEvent.uChar.AsciiChar;
                    }
                } else {
                    LARGE_INTEGER release_time;
                    QueryPerformanceCounter(&release_time);
                    last_release_time = release_time;
                    last_event_was_release = TRUE;
                    if (input_record.Event.KeyEvent.uChar.AsciiChar != '\0') {
                        printf("'%c' key pressed for %.3f ms\n", input_record.Event.KeyEvent.uChar.AsciiChar,
                        (double)(release_time.QuadPart - start_time.QuadPart) / frequency.QuadPart * 1.0);
                    } else {
                        printf("Key pressed for %.3f s\n", (release_time.QuadPart - start_time.QuadPart) / frequency.QuadPart * 1.0);
                    }
                }
            } 
        }

        if (GetAsyncKeyState(VK_RETURN) & 1) {
            
            printf("\n==============================================================================\n");
            printf("\n Keys pressed ");
            for (int i = 0; i < key_count; i++) {
                printf("%c ", keys[i]);
            }
            printf("\n");
            
            // Output the intervals between key presses
            printf(" intervals between key presses: ");
            for (int i = 0; i < key_count - 2; i++) {
                printf("%.3fs ", intervals[i]);
            }
            printf("\n");
            
            break;
        }
    }

    return 0;
} 
搜索更多相关主题的帖子: printf 密码 验证 Event key 
2023-03-26 15:56
快速回复:二次的密码验证机制
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046000 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved