21xrx.com
2024-04-27 06:50:38 Saturday
登录
文章检索 我的文章 写文章
C 中的验证码程序
2021-07-08 06:59:05 深夜i     --     --
C

生成验证码的 C 程序,验证码是使用算法生成的随机字符串。 我们将在程序中使用随机函数。 这些用于在网站上检查是否人在操作网站。

C验证码程序

#include <stdlib.h>
#include <dos.h>
#include <graphics.h>


int main()
{
  int i = 0, key, n, x, gd = DETECT, gm;
  char a[10];

  initgraph(&gd, &gm, "C:\\TC\\BGI");

  x = getmaxx()/2;

  settextstyle(SCRIPT_FONT, HORIZ_DIR, 5);
  settextjustify(CENTER_TEXT, CENTER_TEXT);
  setcolor(GREEN);
  outtextxy(x, 20, "CAPTCHA");
  settextstyle(SCRIPT_FONT, HORIZ_DIR, 2);
  outtextxy(x, 125, "Press any key to change the generated \"captcha\"");
  outtextxy(x, 150, "Press escape key to exit...");

  setcolor(WHITE);
  setviewport(100, 200, 600, 400, 1);
  setcolor(RED);
  randomize();

  while (1)
  {
    while (i < 6)
    {
      n = random(3);

      if (n == 0)
        a[i] = 65 + random(26);    /* 65 is the ASCII value of A */
      else if (n == 1)
        a[i] = 97 + random(26);    /* 97 is the ASCII value of a */
      else
        a[i] = 48 + random(10);    /* 48 is the ASCII value of 0 */
      i++;
    }
    a[i] = '\0';
    outtextxy(210, 100, a);
    key = getch();

    if (key == 27)  /* escape key */
      exit(0);
    clearviewport();
    i = 0;
  }
}

 

  
  
下一篇: C源代码

评论区

{{item['qq_nickname']}}
()
回复
回复