#include <afx.h>
#include <afxwin.h> // MFC核心和标准组件
bool IsPasswordValid(const CString& password) {
if (password.GetLength() < 6) {
return false; // 密码长度不足6位
}
bool hasDigit = false;
bool hasLower = false;
bool hasUpper = false;
bool hasSymbol = false;
for (int i = 0; i < password.GetLength(); ++i) {
TCHAR ch = password[i];
if (_istdigit(ch)) {
hasDigit = true;
} else if (_istlower(ch)) {
hasLower = true;
} else if (_istupper(ch)) {
hasUpper = true;
} else if (_istpunct(ch)) {
hasSymbol = true;
}
}
return hasDigit && hasLower && hasUpper && hasSymbol;
}
CString::GetLength
来获取密码长度,并首先检查是否至少有6个字符。_istdigit
, _istlower
, _istupper
, _istpunct
函数来判断字符的类型。这个函数是基于MFC和C++标准库的,因此在包含这些函数的环境中应该可以正常工作。记得在实际应用中,你可能还需要考虑其他安全性因素。
原文地址:https://blog.csdn.net/chenhao0568/article/details/134654768
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_37836.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!