Giter Club home page Giter Club logo

captchagen's Introduction

Captcha Generator - .NET

A simple class library used for generating image captcha with audio dynamically without the need for external database or library.

Compatibility with .Net 4.0 and above versions.

Introduction

This project is also available as a nuget package.
Install the latest package by entering the following command in Package Manager Console

Install-Package CaptchaGen

Visit this link for previous versions

Alternatively you can clone this repo and build it yourself and refer this project in your main project.

Usage

Captcha string Generation

Generate captcha strings using CaptchaCodeFactory class. For example, the following snippet generates captcha string with 8 character length. Captcha string will contain alphanumeric characters generated with the help of RNGCryptoServiceProvider class to ensure randomness.

String captchaCode = CaptchaCodeFactory.GenerateCaptchaCode(8)

Image Generation

ImageFactory class generates the captcha image with the specified captcha string value. ImageFactory.GenerateImage(string) returns a Stream object that contains the image.

Following example snippet generates and serves the captcha image as an HttpResponseMessage

var imageStream = ImageFactory.GenerateImage(id);
imageStream.Position = 0;
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(imageStream);
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/jpeg");
return response;

Audio Generation

AudioFactory class generates the audio data for a specified captcha string value. It utilizes SpeechSynthesizer class to generate the audio data. AudioFactory.GenerateAudio(string) returns a stream object that contains the audio data

The following example generates and serves the audio as a response for an incoming request

HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
var audioStream = AudioFactory.GenerateAudio(id);
audioStream.Position = 0;
response.Content = new StreamContent(audioStream);
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("audio/wav");
return response;

Contribution

You are welcome to contribute to the project by adding new features and improving the existing ones. Fork the project and create a pull request with your features.

License

MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.