Как сделать простую капчу без внешних сервисов
Суть - создаем случайных 2 числа, сохраняем в базе. ключ Guid передаем на форму через Hidden поле.
В saveItem извлекаем по ключу и сравниваем исходную сумму и то, что ввел пользователь по текстовому описанию.
Поля формы:
- sum Строка
- guid hidden
Разметка формы:
{form-title}
{colwithlabel-name}
<div class="badge badge-info">
{form-subtitle}
</div>
{colwithlabel-sum}
{form-button}
{colcontrol-guid}
GetItem формы:
CREATE PROCEDURE [dbo].[fm_watch_captcha_getItem]
@itemID int,
@username nvarchar(256)
AS
BEGIN
declare @guid uniqueidentifier = newID()
declare @s1 int = FLOOR(RAND()*70+1), @s2 int = FLOOR(RAND()*1+20)
insert as_checkForms(guid, s1,s2) values (@guid, @s1,@s2)
select @guid guid
select dbo.as_numPropis(@s1, 1) + ' плюс ' + dbo.as_numPropis(@s2, 1) Subtitle
END
SaveItem формы:
CREATE PROCEDURE [dbo].[fm_watch_captcha_saveItem]
@username nvarchar(256),
@itemID int,
@parameters ExtendedDictionaryParameter readonly
AS
BEGIN
declare @guid nvarchar(256) = (select try_convert(uniqueidentifier, value2) from @parameters where [key] = 'guid')
declare @sum int = (select try_cast(value2 as int) from @parameters where [key] = 'sum')
declare @savedSum int = (select s1 + s2 from as_checkForms where guid = @guid)
if(@sum <> @savedSum) begin
select 'Неверно указана сумма' msg, 0 result
return
end
-- 1 SELECT (Result, Msg)
select 1 Result, 'Операция прошла успешно' Msg
END
Для работы формы необходима таблица as_checkForms:
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name= 'as_checkForms' and xtype='U') BEGIN
CREATE TABLE [dbo].[as_checkForms]
(
[id] [int] IDENTITY(1,1) NOT NULL
CONSTRAINT [PK_as_checkForms] PRIMARY KEY CLUSTERED ( [id] ASC )
) ON [PRIMARY]
print 'Создана таблица as_checkForms '
END
GO
IF COL_LENGTH( 'as_checkForms', 'guid') IS NULL BEGIN
ALTER TABLE as_checkForms
ADD [guid] uniqueidentifier NOT NULL
END
IF COL_LENGTH( 'as_checkForms', 's1') IS NULL BEGIN
ALTER TABLE as_checkForms
ADD [s1] int NOT NULL
END
IF COL_LENGTH( 'as_checkForms', 's2') IS NULL BEGIN
ALTER TABLE as_checkForms
ADD [s2] int NULL
END
И последнее - функция, переводящая число в строковую надпись:
USE [demo]
GO
/****** Object: UserDefinedFunction [dbo].[as_numPropis] Script Date: 21.11.2022 11:38:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER function [dbo].[as_numPropis] (@num BIGINT, @isMaleGender bit=1)
returns varchar(255)
as
begin
declare @nword varchar(255), @th tinyint, @gr smallint, @d3 tinyint, @d2
tinyint, @d1 tinyint
if @num<0 return '*** Error: Negative value' else if @num=0 return 'Ноль'
/* особый случай */
while @num>0
begin
set @th=IsNull(@th,0)+1 set @gr=@num%1000 set @num=(@num-@gr)/1000
if @gr>0
begin
set @d3=(@gr-@gr%100)/100
set @d1=@gr%10
set @d2=(@gr-@d3*100-@d1)/10
if @d2=1 set @d1=10+@d1
set @nword=
case @d3
when 1 then ' сто'
when 2 then ' двести'
when 3 then ' триста'
when 4 then ' четыреста'
when 5 then ' пятьсот'
when 6 then ' шестьсот'
when 7 then ' семьсот'
when 8 then ' восемьсот'
when 9 then ' девятьсот'
else ''
end +
case @d2
when 2 then ' двадцать'
when 3 then ' тридцать'
when 4 then ' сорок'
when 5 then ' пятьдесят'
when 6 then ' шестьдесят'
when 7 then ' семьдесят'
when 8 then ' восемьдесят'
when 9 then ' девяносто'
else ''
end +
case @d1
when 1 then (case when @th=2 or (@th=1 and @isMaleGender=0) then ' одна' else ' один' end)
when 2 then (case when @th=2 or (@th=1 and @isMaleGender=0) then ' две' else ' два' end)
when 3 then ' три'
when 4 then ' четыре'
when 5 then ' пять'
when 6 then ' шесть'
when 7 then ' семь'
when 8 then ' восемь'
when 9 then ' девять'
when 10 then ' десять'
when 11 then ' одиннадцать'
when 12 then ' двенадцать'
when 13 then ' тринадцать'
when 14 then ' четырнадцать'
when 15 then ' пятнадцать'
when 16 then ' шестнадцать'
when 17 then ' семнадцать'
when 18 then ' восемнадцать'
when 19 then ' девятнадцать'
else ''
end +
case @th
when 2 then ' тысяч' + (
case
when @d1=1 then 'а'
when @d1 in (2,3,4)
then 'и'
else ''
end)
when 3 then ' миллион'
when 4 then ' миллиард'
when 5 then ' триллион'
when 6 then ' квадрилион'
when 7 then ' квинтилион'
else ''
end +
case
when @th in (3,4,5,6,7) then (
case
when @d1=1 then ''
when @d1 in (2,3,4) then 'а'
else 'ов'
end)
else ''
end
+ IsNull(@nword,'')
end
end
return upper(substring(@nword,2,1))+substring(@nword,3,len(@nword)-2)
end
В чем выгода для бизнеса?
Простая капча на основе арифметического примера. Защищает формы от ботов без использования внешних сервисов, экономит деньги.Последние обновления
Страницы 04.04.2026
Форма 26.03.2026
Форма 24.02.2026
05.02.2026
Форма 25.01.2026
Форма 12.12.2025
Интеграции 24.11.2025
Разное 24.11.2025
Форма 15.11.2025
Визуализация 02.11.2025
Таблица 08.10.2025
Форма 26.09.2025
Таблица 23.09.2025
Разное 23.08.2025
Таблица 21.08.2025
Форма 20.08.2025
Таблица 18.08.2025
Таблица 21.06.2025
SQL-инструмент для создания личных кабинетов на сайте
Платформа Falcon Space
Это снижение стоимости владения
за счет меньшего количества людей для поддержки
Это быстрое внесение изменений
по ходу эксплуатации программы
Это современный интерфейс
полная адаптация под мобильные устройства