Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Web.Mvc;
namespace YourNamespace.Controllers
{
public class CaptchaController : Controller
{
private const string CaptchaSessionKey = "CaptchaCode";
public ActionResult Index()
{
// Generate a new CAPTCHA code
string captchaCode = GenerateCaptchaCode();
// Save the CAPTCHA code in session
Session[CaptchaSessionKey] = captchaCode;
// Generate the CAPTCHA image
byte[] captchaImage = GenerateCaptchaImage(captchaCode);
// Return the CAPTCHA image as a FileResult
return File(captchaImage, "image/png");
}
[HttpPost]
public ActionResult Validate(string userInput)
{
// Retrieve the CAPTCHA code from session
string captchaCode = Session[CaptchaSessionKey] as string;
// Check if the user input matches the CAPTCHA code
bool isValid = userInput.Equals(captchaCode, StringComparison.OrdinalIgnoreCase);
// You can use the isValid flag to perform further actions, like redirecting or showing a message
return Content(isValid ? "Valid CAPTCHA" : "Invalid CAPTCHA");
}
private string GenerateCaptchaCode()
{
// Generate a random CAPTCHA code (you can customize this method further if needed)
Random random = new Random();
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, 6).Select(s => s[random.Next(s.Length)]).ToArray());
}
private byte[] GenerateCaptchaImage(string captchaCode)
{
// Generate the CAPTCHA image (you can customize the appearance and font)
using (Bitmap bitmap = new Bitmap(200, 50))
{
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.Clear(Color.White);
Font font = new Font("Arial", 20, FontStyle.Bold);
PointF point = new PointF(10f, 10f);
graphics.DrawString(captchaCode, font, Brushes.Black, point);
}
// Convert the bitmap to a byte array
using (MemoryStream stream = new MemoryStream())
{
bitmap.Save(stream, ImageFormat.Png);
return stream.ToArray();
}
}
}
}
}
@{
ViewBag.Title = "CAPTCHA Validation";
}
<h2>CAPTCHA Validation</h2>
@using (Html.BeginForm("Validate", "Captcha", FormMethod.Post))
{
<div>
<img src="@Url.Action("Index", "Captcha")" alt="CAPTCHA Image" />
<br />
<label for="captchaInput">Enter the CAPTCHA code:</label>
<input type="text" id="captchaInput" name="userInput" />
<br />
<input type="submit" value="Submit" />
<a href="@Url.Action("Index", "Captcha")">Refresh CAPTCHA</a>
</div>
}
<system.web>
<sessionState mode="InProc" />
<!-- Other configurations -->
</system.web>
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team