captcha

Struct RngCaptcha

Source
pub struct RngCaptcha<T> { /* private fields */ }
Expand description

A CAPTCHA.

Implementations§

Source§

impl<T: Rng + RngCore> RngCaptcha<T>

Source

pub fn from_rng(rng: T) -> RngCaptcha<T>

Source

pub fn new() -> Captcha

Returns an empty CAPTCHA.

Source

pub fn apply_filter<F: Filter>(&mut self, f: F) -> &mut Self

Applies the filter f to the CAPTCHA.

This method is used to add noise, grids, etc or to transform the shape of the CAPTCHA.

Source

pub fn set_font<F: Font + 'static>(&mut self, f: F) -> &mut Self

Sets another font that is used for the characters.

Calling this method does not have an effect on the font of the characters which have already been added to the CAPTCHA. The new font is only applied to the characters which are written to the CAPTCHA after this method is called.

If characters have been set via set_chars(), this method will overwrite the setting.

Source

pub fn set_color(&mut self, color: [u8; 3]) -> &mut Self

Source

pub fn save(&self, p: &Path) -> Result<()>

Saves the CAPTCHA to a image file.

The format that is written is determined from the filename’s extension. On error Err is returned.

Source

pub fn set_chars(&mut self, c: &[char]) -> &mut Self

Sets the characters that should be used when generating a CAPTCHA.

Important: The characters have to exist for the current font. You can get all characters which are supported by the current font by calling supported_chars().

Source

pub fn add_char(&mut self) -> &mut Self

Adds a random character using the current font.

Source

pub fn add_text_area(&mut self) -> &mut Self

Adds a red box to the CAPTCHA representing the area which contains text.

Source

pub fn text_area(&self) -> Geometry

Returns the geometry of the area which contains text in the CAPTCHA.

Source

pub fn extract(&mut self, area: Geometry) -> &mut Self

Crops the CAPTCHA to the given geometry.

Source

pub fn view(&mut self, w: u32, h: u32) -> &mut Self

Crops the CAPTCHA to the given width and height with the text centered withing this box.

Source

pub fn chars(&self) -> Vec<char>

Returns the characters that have been added to this CAPTCHA.

Source

pub fn chars_as_string(&self) -> String

Returns the characters that have been added to this CAPTCHA collected into a string.

Source

pub fn add_chars(&mut self, n: u32) -> &mut Self

Adds the given number of random characters to the CAPTCHA using the current font.

Source

pub fn as_wav(&self) -> Vec<Option<Vec<u8>>>

Returns for each letter in the CAPTCHA an audio in WAV format.

Warning: Currently this feature is rather limited. The same audio data is returned for the same letter, i.e. no noise is added. Someone could solve the CAPTCHA by simply having the audio for each letter and comparing them with the current challenge.

Source

pub fn as_png(&self) -> Option<Vec<u8>>

Returns the CAPTCHA as a png image.

Returns None on error.

Source

pub fn as_base64(&self) -> Option<String>

Source

pub fn as_tuple(&self) -> Option<(String, Vec<u8>)>

Returns a tuple which contains the characters that have been added to this CAPTCHA as a string and the image encoded as a PNG.

Returns None on error.

Source

pub fn supported_chars(&self) -> Vec<char>

Returns the supported characters of the current font.

Auto Trait Implementations§

§

impl<T> Freeze for RngCaptcha<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for RngCaptcha<T>

§

impl<T> !Send for RngCaptcha<T>

§

impl<T> !Sync for RngCaptcha<T>

§

impl<T> Unpin for RngCaptcha<T>
where T: Unpin,

§

impl<T> !UnwindSafe for RngCaptcha<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V