我正在用 java 构建一个桌面应用程序,我需要登录的用户名。
我正在使用 System.getProperty("user.name")
获取用户名。
但这可以通过使用
来欺骗Properties p = System.getProperties();
p.put("user.name", "XYZ");
System.setProperties(p);
或通过
-Duser.name=someothername
我怎样才能防止这种欺骗或任何替代方法以安全的方式登录用户名。 桌面应用程序独立于平台。
最佳答案
系统属性不是环境变量。使用 System.getenv("USERNAME")
作为环境变量。 System.properties
仍然可以由用户在 java 命令行上使用 java -Duser.name=someoneelse
进行设置。
关于java - 如何防止 System.getProperty ("user.name") 被欺骗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39444860/