Difference between revisions of "Get the user name"

From CodeCodex

(Java)
 
(Implementations)
 
Line 2: Line 2:
 
===Java===  
 
===Java===  
 
In application :  
 
In application :  
<highlightsyntax language="java122">
+
<pre class="java">
 
public class Test {
 
public class Test {
 
     public static void main(String args[]) {     
 
     public static void main(String args[]) {     
Line 8: Line 8:
 
     }
 
     }
 
}     
 
}     
</highlightsyntax>
+
</pre>
 
will print the current user. You can't use this technique to secure your application since it is very to spoof.  
 
will print the current user. You can't use this technique to secure your application since it is very to spoof.  
 
You just need to specify a "user.name" from the command line.  
 
You just need to specify a "user.name" from the command line.  
<highlightsyntax language="java122">
+
<pre class="java">
 
> java -Duser.name=Elvis Test
 
> java -Duser.name=Elvis Test
 
Elvis
 
Elvis
</highlightsyntax>
+
</pre>
 
As an alternative with JDK1.5,  
 
As an alternative with JDK1.5,  
<highlightsyntax language="java122">
+
<pre class="java">
 
public class Test {
 
public class Test {
 
   public static void main(String args[]) {
 
   public static void main(String args[]) {
Line 25: Line 25:
 
   }
 
   }
 
}
 
}
</highlightsyntax>
+
</pre>
 
--------------------------------------------------------------------------------
 
--------------------------------------------------------------------------------
 
In Applet there is no way unless you ask for it or use a signed applet. If you have access to a server-side, something like an ASP page can be used to detect the current NT user name if the client and the server are configured correcty (SSO).  
 
In Applet there is no way unless you ask for it or use a signed applet. If you have access to a server-side, something like an ASP page can be used to detect the current NT user name if the client and the server are configured correcty (SSO).  
Line 31: Line 31:
 
See this [http://www.rgagnon.com/javadetails/java-0441.html related HowTo] for a JSP hack!  
 
See this [http://www.rgagnon.com/javadetails/java-0441.html related HowTo] for a JSP hack!  
  
 +
=== Tcl ===
 +
<pre class="tcl">
 +
set user $::env(USERNAME)
 +
</pre>
 
[[Category:Java]]
 
[[Category:Java]]
 +
[[Category:Tcl]]

Latest revision as of 18:30, 18 February 2011

Implementations[edit]

Java[edit]

In application :

public class Test {
    public static void main(String args[]) {    
      System.out.println( System.getProperty("user.name") );
    }
}    

will print the current user. You can't use this technique to secure your application since it is very to spoof. You just need to specify a "user.name" from the command line.

> java -Duser.name=Elvis Test
Elvis

As an alternative with JDK1.5,

public class Test {
  public static void main(String args[]) {
    com.sun.security.auth.module.NTSystem NTSystem = new
            com.sun.security.auth.module.NTSystem();
    System.out.println(NTSystem.getName());
    System.out.println(NTSystem.getDomain());
  }
}

In Applet there is no way unless you ask for it or use a signed applet. If you have access to a server-side, something like an ASP page can be used to detect the current NT user name if the client and the server are configured correcty (SSO).


See this related HowTo for a JSP hack!

Tcl[edit]

set user $::env(USERNAME)