RSS

Example of Programatic Security

05 Apr
<%@ page import="sun.misc.*" %>
<%! 
public void m1(HttpServletResponse res)
{
	res.setStatus(401);
	res.setHeader("WWW-Authenticate","BASIC realmname=enter username and password");
}
%>
<% 
	String s=request.getHeader("Authorization");
	if(s !=null)
	{
		String encodeddata =s.substring(6);

		BASE64Decoder obj=new BASE64Decoder();
		String up=new String(obj.decodeBuffer(encodeddata));

		String [] arr=up.split(":");
		if(arr[0].equals("ad") && arr[1].equals("ad") ) 
		{
			out.println("Welcome to the page" );
		}
		else
		{
			m1(response);
		}
	}
	else
	{
			m1(response);
	}
%>

 
Leave a comment

Posted by on April 5, 2016 in Example

 

Leave a comment