📄 pwldlg.cpp
字号:
/******************************************************************* * * Copyright (c) 1994-1999 Jetico, Inc., Finland * All rights reserved. * * File: pwdlg.cc * Revision: $Id: pwldlg.cpp,v 1.1 2005/05/12 09:51:39 crypt Rel-1.6-3 $ * Created: * Description: implementation of procedures that support * dialog for accepting user's password and * support generation of seed value for * random key generation * *******************************************************************/#include <stdio.h>#include <unistd.h>#include <string.h>#include <bc_types.h>#include "kg_defs.h"#include "kg_misc.h"#include "pwldlg.h"char pwldlg_cpp[]="$Id: pwldlg.cpp,v 1.1 2005/05/12 09:51:39 crypt Rel-1.6-3 $";/* Global data */// DWORD SeedCounter, SeedLength;/* Exported procedures */DWORD GetPassword( char *text, // Text, containing filename of the container char *caption, // Caption of the "get password" dialog char *password ){ char *pwd; if (text) printf ("%s\n",text); if (! (pwd = getpass (caption))) return ERROR_INTERNAL_PROBLEM; strncpy(password,pwd,PASSWORD_MAXIMUM_LENGTH); ShredData( (BYTE *)pwd, strlen(pwd) ); return ERROR_NO;}DWORD GetPasswordWithVerification( char *text, // Text, containing filename of the container char *caption, // Caption of the "get password" dialog window char *password ){ char *pwd; if (text) printf ("%s\n",text); do if (! (pwd = getpass (caption))) return ERROR_INTERNAL_PROBLEM; while (strlen(pwd) < PASSWORD_MINIMUM_LENGTH && printf("Passwword too short.\n")); strncpy(password,pwd,PASSWORD_MAXIMUM_LENGTH); ShredData( (BYTE *)pwd, strlen(pwd) ); if (! (pwd = getpass ("Verify password: "))) return ERROR_INTERNAL_PROBLEM; if (strlen(pwd) != strlen(password) || strncmp(pwd,password,strlen(pwd) < PASSWORD_MAXIMUM_LENGTH ? strlen(password) : PASSWORD_MAXIMUM_LENGTH)) return ERROR_USER_PASSWORDS_MISMATCH; ShredData( (BYTE *)pwd, strlen(pwd) ); return ERROR_NO;}DWORD GetSeedValue( BYTE *seed, DWORD seedLength ){ FILE *fd; if (! (fd=fopen("/dev/random","r"))) return ERROR_INTERNAL_PROBLEM; for ( DWORD i=0; i<seedLength; i++ ) seed[i]=(char)fgetc(fd); fclose (fd); return ERROR_NO;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -