Foros de discusión

How to remove NoiseProducer Line from the Captcha?

thumbnail
Anuvab Ghosh, modificado hace 8 años.

How to remove NoiseProducer Line from the Captcha?

Regular Member Mensajes: 130 Fecha de incorporación: 18/04/15 Mensajes recientes
Hi,

I want to remove the Curved or Straight line from the captcha.
i.e., I do not want to use the NoiseProducer lines in the captcha, want to display only the text or number clearly.

I have tried to comment out with the property captcha.engine.simplecaptcha.noise.producers and then setting value none, null and false to the property. But did not get the desired result.

Please give the solution.

This is very urgent for me.

Thanks in advance.

Regards,
Anuvab
thumbnail
Anuvab Ghosh, modificado hace 8 años.

RE: How to remove NoiseProducer Line from the Captcha?

Regular Member Mensajes: 130 Fecha de incorporación: 18/04/15 Mensajes recientes
Please reply about this matter.

Moreover, you can explain how to customize the color and the thickness of the StraightLineNoiseProducer.

Thanks in advance.

Regards,
Anuvab
Kushagra Khanna, modificado hace 8 años.

RE: How to remove NoiseProducer Line from the Captcha?

Junior Member Mensajes: 45 Fecha de incorporación: 28/12/14 Mensajes recientes
Hi Anuvab,

You can use following code in your portal ext.properties & then you have restart your server.

captcha.engine.impl=com.liferay.portal.captcha.simplecaptcha.SimpleCaptchaImpl
captcha.engine.simplecaptcha.background.producers=nl.captcha.backgrounds.TransparentBackgroundProducer
captcha.engine.simplecaptcha.gimpy.renderers=nl.captcha.gimpy.RippleGimpyRenderer
captcha.engine.simplecaptcha.noise.producers=nl.captcha.noise.StraightLineNoiseProducer


This may improve your captcha visibility.

Regards,
Kushagra
thumbnail
Anuvab Ghosh, modificado hace 8 años.

RE: How to remove NoiseProducer Line from the Captcha?

Regular Member Mensajes: 130 Fecha de incorporación: 18/04/15 Mensajes recientes
Thanks for the reply.

Kushagra Khanna:
...
captcha.engine.simplecaptcha.noise.producers=nl.captcha.noise.StraightLineNoiseProducer
...


In this case a red line is shown in the captcha image, I do not want to show any noise in the captcha image.
How to remove any type of line(Curved or Straight) from the SimpleCaptcha?
Or, how to customize the Straight line color and thickness?

Thanks in advance.

Regards,
Anuvab
thumbnail
Anuvab Ghosh, modificado hace 8 años.

RE: How to remove NoiseProducer Line from the Captcha?

Regular Member Mensajes: 130 Fecha de incorporación: 18/04/15 Mensajes recientes
Please give some response about this matter.
thumbnail
Manish Yadav, modificado hace 8 años.

RE: How to remove NoiseProducer Line from the Captcha? (Respuesta)

Expert Mensajes: 493 Fecha de incorporación: 26/05/12 Mensajes recientes
Anuvab Ghosh:
Please give some response about this matter.



Hello Anuvab Ghosh,

Liferay Using simple captcha simplecaptcha.jar , it have only 2 classes for noise in image , so default no way to do

1) nl.captcha.noise.CurvedLineNoiseProducer.class
2) nl.captcha.noise.StraightLineNoiseProducer.class

So you can write your own java class and extend StraightLineNoiseProducer class and then create jar file and copy into tomcat/webapps/root/lib/
I have added sample code ,It may help you ,I have only changed line width to 0.
In portal-ext.properties you have to add your own captcha class.
captcha.engine.simplecaptcha.noise.producers=com.nl.captcha.noise.WithOutAnyNoise

I'm adding sample code for your help

package com.nl.captcha.noise;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.security.SecureRandom;

import nl.captcha.noise.StraightLineNoiseProducer;

public class WithOutAnyNoise extends StraightLineNoiseProducer{
	private final Color _color;
    private final int _thickness;
    private final SecureRandom _gen = new SecureRandom();

    /**
     * I have changed value from default value 4 to 0, so it will not show any line in captcha
     */
    public WithOutAnyNoise() {
 this(Color.BLACK, 0);
    }

    public WithOutAnyNoise(Color color, int thickness) {
        _color = color;
        _thickness = thickness;
    }

    public void makeNoise(BufferedImage image) {
        Graphics2D graphics = image.createGraphics();
        int height = image.getHeight();
        int width = image.getWidth();
        int y1 = _gen.nextInt(height) + 1;
        int y2 = _gen.nextInt(height) + 1;
        drawLine(graphics, y1, width, y2);
    }

    private void drawLine(Graphics g, int y1, int x2, int y2) {
        int X1 = 0;

        // The thick line is in fact a filled polygon
        g.setColor(_color);
        int dX = x2 - X1;
        int dY = y2 - y1;
        // line length
        double lineLength = Math.sqrt(dX * dX + dY * dY);

        double scale = _thickness / (2 * lineLength);

        // The x and y increments from an endpoint needed to create a
        // rectangle...
        double ddx = -scale * dY;
        double ddy = scale * dX;
        ddx += (ddx > 0) ? 0.5 : -0.5;
        ddy += (ddy > 0) ? 0.5 : -0.5;
        int dx = (int) ddx;
        int dy = (int) ddy;

        // Now we can compute the corner points...
        int xPoints[] = new int[4];
        int yPoints[] = new int[4];

        xPoints[0] = X1 + dx;
        yPoints[0] = y1 + dy;
        xPoints[1] = X1 - dx;
        yPoints[1] = y1 - dy;
        xPoints[2] = x2 - dx;
        yPoints[2] = y2 - dy;
        xPoints[3] = x2 + dx;
        yPoints[3] = y2 + dy;

        g.fillPolygon(xPoints, yPoints, 4);
    }
}


you can use this attached jar as well, you have to only copy below jar into your tomcat/webapss/ROOT/lib folder and add below line into your portal-ext.properites

captcha.engine.simplecaptcha.noise.producers=com.nl.captcha.noise.WithOutAnyNoise

Archivos adjuntos:

thumbnail
Anuvab Ghosh, modificado hace 8 años.

RE: How to remove NoiseProducer Line from the Captcha?

Regular Member Mensajes: 130 Fecha de incorporación: 18/04/15 Mensajes recientes
Hi,

Thank you very much for your effort and help. Its really very helpful for me and almost fulfill my requirement.
Its working fine in tomcat and jboss server both with liferay-6.2.
I put your captcha.jar in liferay-portal-6.2-ce-ga5/jboss-7.1.1/standalone/deployments/ROOT.war/WEB-INF/lib for JBoss Server and in liferay-portal-6.2-ce-ga5/tomcat-7.0.62/webapps/ROOT/WEB-INF/lib for Tomcat Server.
Then paste captcha.engine.simplecaptcha.noise.producers=com.nl.captcha.noise.WithOutAnyNoise in the portal-ext.properties.
I have attached the latest look of the captcha.

Thanks again Manish.

Regards,
Anuvab