Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-05-2008, 06:31 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 234
Rep Power: 2
Eku is on a distinguished road
Default JSP Auto Log -In
Do anyone know how can i make this thing work? here is the code and the Story. . .

Code:
<%-- 
    Document   : index
    Created on : 
    Author     : Eku
--%>


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <%
        String ua = request.getHeader( "User-Agent" );
        boolean isMSIE = ( ua != null && ua.indexOf( "MSIE" ) != -1 );
        response.setHeader( "Vary", "User-Agent" );

        String hehe = "";
        %>
        <script language="JavaScript">
        <!--
        var nHist = window.history.length;
        if(window.history[nHist] != window.location)
          window.history.forward();
        //-->
        </script>
        <%@ page import="sun.misc.BASE64Encoder" %>
        <%@ page import="java.io.*" %>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Toll ReBilling System</title>
</head>
    <body bgproperties="fixed" background="BGLOGO.jpg" topmargin=3 link="#7E7E7E" vlink="#000000" alink="#FF9D9D">


<BR><div id="Ulo" style="height:150px; width:100%" align="center">
    <h1>Toll ReBilling System</h1>
        <h2>Log-In Page</h2></div>
        <div id="Katawan" style="height:375px; width:100%" align="center">
            <form action="loginservlet?action=LOGIN" method="post">
            <%String Username = null; int flag = 0;
                String auth = request.getHeader("Authorization");
                if (auth == null) {
                        response.setStatus(response.SC_UNAUTHORIZED);
                        response.setHeader("WWW-Authenticate", "NTLM");
                        return;
                }
                if (auth.startsWith("NTLM ")) { 
                        byte[] msg = 
                           new sun.misc.BASE64Decoder().decodeBuffer(auth.substring(5));
                        int off = 0, length, offset;
                        String s;

                        if (msg[8] == 1) { 
                            off = 18;

                            byte z = 0;
                            byte[] msg1 =
                                {(byte)'N', (byte)'T', (byte)'L', (byte)'M', (byte)'S',
                                (byte)'S', (byte)'P', z,
                                (byte)2, z, z, z, z, z, z, z,
                                (byte)40, z, z, z, (byte)1, (byte)130, z, z,
                                z, (byte)2, (byte)2, (byte)2, z, z, z, z, // 
                                z, z, z, z, z, z, z, z};
                            // 
                            response.setStatus(response.SC_UNAUTHORIZED);
                            response.setHeader("WWW-Authenticate", "NTLM " 
                               + new sun.misc.BASE64Encoder().encodeBuffer(msg1).trim());
                            return;
                        } 
                        else if (msg[8] == 3) { 
                                off = 30;
                                length = msg[off+17]*256 + msg[off+16];
                                offset = msg[off+19]*256 + msg[off+18];
                                s = new String(msg, offset, length);
                        } 
                        else
                                return;

                        length = msg[off+1]*256 + msg[off];
                        offset = msg[off+3]*256 + msg[off+2];
                        s = new String(msg, offset, length);
                        length = msg[off+9]*256 + msg[off+8];
                        offset = msg[off+11]*256 + msg[off+10];
                        s = new String(msg, offset, length);
                        Username = s;
                        } //http://www.rgagnon.com/javadetails/java-0441.html
                

                               String line;
                    BufferedReader in = new BufferedReader(new FileReader("E:\\TRBS\\UsersData\\users.txt"));
                    flag = 0;
                    while ((line = in.readLine()) != null) {
                    if (Username.equalsIgnoreCase(line)){
                            flag = 1;
                        }else{
                            
                        }
                    }
                    in.close();
                
                
        String Message = (String) request.getAttribute("mess");
            if (Username.equals(null)){
                Message = "UNAUTHORIZED ACCESS";
                hehe = "disabled";
            } else if ((!Username.equals(null))&&(flag==1)){
                Message = "<h2>Welcome " + Username 
                        + "</h2><BR><h5>Please press OK to continue</h5>"
                        + "<input type=\"submit\" value=\"   Ok   \"/>";
            }
            if (!isMSIE){
                Message = "Browser Not Supported";
                hehe = "disabled";
            }
        %>
        
            <table>
                <tr>
                    <td><%=Message%></td>
                    <td><input type = "hidden" name="user" value = <%=Username%> ></td>        
                </tr>

            </table> 
            
        </form>
        </div>
    
    
    <div id="ilalim" style="position:absolute; top:550px; width:100%">
        <CENTER><a href="http://www.pldt.com.ph/" title="visit website">Philippine Long Distance Telephone Company (PLDT)</a> 
        2008 All rights reserved.</CENTER>
    </div>
    
    <%--
    This example uses JSTL, uncomment the taglib directive above.
    To test, display the page like this: index.jsp?sayHello=true&name=Murphy
    --%>
    <%--
    <c:if test="${param.sayHello}">
        <!-- Let's welcome the user ${param.name} -->
        Hello ${param.name}!
    </c:if>
    --%>
    
    </body>
</html>
This code is for IE only. I have this part of the code that gives the ??? in my head
Code:
if (Username.equalsIgnoreCase(line)){
                            flag = 1;
                        }
Username is eku
the file contains eku

The output of both strings are "eku" and "eku" they are the same. Is there any problem with the use of encoding? can anyone help me please . . . ^_^ Thanks
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 09-06-2008, 05:35 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 540
Rep Power: 3
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Default
For me,

String's equalsIgnoreCase() method should only be use if the Object that is being compared in another Object is a String.... No other than that.....

(theory)
if it was converted in bytes(depends on the platform), then that bytes are passed on other platform, Converted again to String, It may affect the encoding.... Im not sure(though i don't really know the exact mechanism)

try to use Collator class
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-12-2008, 06:53 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 234
Rep Power: 2
Eku is on a distinguished road
Default
Its ok now. i found the solution although its not java. ^_^ i used javascript and ActiveX function to get the domain and username and pass it to my servlet. Its kind of tricky but the code is much short about 5 lines to get the values and submit it to my servlet. But the problem is it works only for I.E. 7 and up so i had to make some restrictions on that, about almost everyone here uses I.E. except me i prefer other browsers. That is the legal browser in our company.

And another info for JSP, refrain from using .trim() and .substring() function. . . uhmmm in my case sometimes i works most of the times it doesnt. i just used the long method which is the Char Array
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-18-2008, 04:58 AM
Member
 
Join Date: Sep 2008
Posts: 2
Rep Power: 0
nhy520 is on a distinguished road
Default
up this way
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto-complete/Auto-fix for custom statement dark_cybernetics Eclipse 0 08-19-2008 12:19 PM
bizarre auto expansion fishtoprecords Suggestions & Feedback 2 07-31-2008 11:52 PM
dynamic auto suggestion freddieMaize Advanced Java 3 07-31-2008 04:20 PM
IDE with auto completion? iceflyin New To Java 8 04-21-2008 02:07 PM
How to create auto-increment Albert Database 2 07-04-2007 06:23 AM


All times are GMT +2. The time now is 10:28 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org