Home Database Mysql Tutorial 自定义的Oracle用户密码效验程序

自定义的Oracle用户密码效验程序

Jun 07, 2016 pm 05:35 PM

Oracle的verify_function_11G函数只是通过一些密码规则来让密码看起来不容易猜到,但一些用户的习惯让所设的密码虽然复杂,但并不

Oracle的verify_function_11G函数只是通过一些密码规则来让密码看起来不容易猜到,但一些用户的习惯让所设的密码虽然复杂,但并不难猜,这时可以用我写的这个程序,把一些常见的易猜的密码放入文件或字典数据库中, 通过程序自动尝试连接Oracle数据库,来效验指定数据密码是否太过易猜或简单,如果数据库用户配置稍严格些,这个程序就不起作用了,所以不太具有实用价值,仅参考使用。

程序用到了 SQLite与 OTL可看:  SQLite编程相关()      OTL的使用() 去了解相关使用方法。

程序代码如下:

/**
* author: xiongchuanliang
* desc: 效验密码是否是使用数据库默认密码,或密码是否太过简单
      程序的参数说明:
        -d 效验是否使用默认用户和密码没改过
  -s 事先在SQLite数据库中存放各类数据库密码,然后依次尝试。
      可通过 “ -s a% “这类来从字典表中过滤出相符合的密码字符串
  -f 从密码文件中读取密码字符串依次尝试
*/

#include
#include
#include
#include

#include "sqlite3.h"


#define OTL_ORA10G
//#define OTL_ORA11G_R2 // Compile OTL 4.0/OCI11.2
#include "otlv4.h" // include the OTL 4 header file

using namespace std;
otl_connect oracledb;

#define MAXLINE 150

#define DICT_DB  "c:\\sqlite\\mydict.db"
#define DICT_FILE "c:/sqlite/mydict.txt"
#define TNS_DBNAME "xcldb"

#define SQL_COUNT  " SELECT count(*) FROM userpwd "
#define SQL_SELECT  " SELECT pwd FROM userpwd "

char arrTestUser[][30] = {"sys","system","test"};
int arrTestUserLen = 3;


//从SQLite只按条件查出密码串放入文件
sqlite3_uint64 getDictDB(char * pWhere);

//初始化OTL
void initOTL();

//连接Oracle数据库
int connectORA(char * connstr);

//从字典文件读入密码字符串尝试连接
bool testConnDB();

//尝试用默认的用户名和密码连接
bool testConnDBDF();

int main(int argc, char* argv[])
{
 printf("==========================\n");
 printf("数据库密码有效性测试!\n");
 printf("==========================\n");

 if(argc==1||argc    printf("请输入运行参数(-f,-d,-s).\n");
   
 //从指定字典文件中查找
 if( strcmp(argv[1],"-f") == 0)
 {
  printf(" -f : 从指定字典文件中查找\n");
  testConnDB();
 }else{

   initOTL();
   //查数据库默认用户密码 
   if( strcmp(argv[1],"-d") == 0)
   {
    printf(" -d : 查数据库默认用户密码 \n");
    testConnDBDF();
   }else if( strcmp(argv[1],"-s") == 0) //从SQLite数据库找出密码
   {

    printf(" -s : 从SQLite数据库找出密码 \n"); 
    if(argc==3)
    {
      printf("过滤条件: %s\n",argv[2]); // %a123%
      char sW[50] = {0};
      //char *s = " where pwd like '%aaa%' ";
      sprintf_s(sW, " where pwd like '%s' ",argv[2]);
      getDictDB(sW);
    }else{
      char *sW = NULL;
      getDictDB(sW);
    }     
    //从数据库中转出的密码文件中读取密码进行尝试
    testConnDB();
   }else{
    printf("请输入(-f,-d,-s)三个参数之一.\n");
   }
 }
 
 return 0;
}

//从SQLite只按条件查出密码串放入文件
sqlite3_uint64 getDictDB(char * pWhere)

 char sqlCount[MAXLINE] = {0};
 char sqlSelect[MAXLINE] = {0}; 

 strcpy_s(sqlCount,SQL_COUNT);
 strcpy_s(sqlSelect,SQL_SELECT);

 if(pWhere != NULL)
 {
  strcat_s(sqlCount,pWhere);
    strcat_s(sqlSelect,pWhere);
 }

 sqlite3 * pDB = NULL;

 //打开路径采用utf-8编码 
    //如果路径中包含中文,,需要进行编码转换 
 // c:\\sqlite\\mydict.db
    int nRes = sqlite3_open(DICT_DB, &pDB); 
    if (nRes != SQLITE_OK) 
    {   
  printf("字典数据库连接失败. %s \n",sqlite3_errmsg(pDB)); 
  return 0;
    } 

 sqlite3_stmt * stmt;
    const char *pTail;    
 sqlite3_uint64 rCount = 0;
 int rc = 0;

 //查询所有数据
    sqlite3_prepare(pDB, sqlCount,-1,&stmt,&pTail);
    int r = sqlite3_step(stmt);               
 if(r == SQLITE_ROW)
 {
    rCount = sqlite3_column_int64( stmt, 0 );  
    printf("共找到%d条字典密码.\n",rCount);
 }
 sqlite3_finalize(stmt);
 
 if(rCount

 //查询所有数据
    sqlite3_prepare(pDB, sqlSelect,-1,&stmt,&pTail);

 
 do{ 

  FILE *fp;
  fopen_s(&fp,DICT_FILE,"w");
  if(fp == NULL)
  {
   printf("字典文件生成失败.\n");
   goto end;
  }

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

Explain InnoDB Full-Text Search capabilities. Explain InnoDB Full-Text Search capabilities. Apr 02, 2025 pm 06:09 PM

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Difference between clustered index and non-clustered index (secondary index) in InnoDB. Difference between clustered index and non-clustered index (secondary index) in InnoDB. Apr 02, 2025 pm 06:25 PM

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values ​​and pointers to data rows, and is suitable for non-primary key column queries.

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you handle large datasets in MySQL? How do you handle large datasets in MySQL? Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

The relationship between mysql user and database The relationship between mysql user and database Apr 08, 2025 pm 07:15 PM

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

See all articles