Results 1 to 4 of 4
  1. #1
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default JSP Auto Log -In

    Do anyone know how can i make this thing work? here is the code and the Story. . .

    Java 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
    Java 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.

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    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
    freedom exists in the world of ideas

  3. #3
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    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.

  4. #4
    nhy520 is offline Member
    Join Date
    Sep 2008
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Auto-complete/Auto-fix for custom statement
    By dark_cybernetics in forum Eclipse
    Replies: 0
    Last Post: 08-19-2008, 11:19 AM
  2. bizarre auto expansion
    By fishtoprecords in forum Suggestions & Feedback
    Replies: 2
    Last Post: 07-31-2008, 10:52 PM
  3. dynamic auto suggestion
    By freddieMaize in forum Advanced Java
    Replies: 3
    Last Post: 07-31-2008, 03:20 PM
  4. IDE with auto completion?
    By iceflyin in forum New To Java
    Replies: 8
    Last Post: 04-21-2008, 01:07 PM
  5. How to create auto-increment
    By Albert in forum JDBC
    Replies: 2
    Last Post: 07-04-2007, 05:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •