Javascript和C#值 [英] Javascript and C# Values

查看:66
本文介绍了Javascript和C#值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI



我需要从客户端获取用户名和密码值,并将其与数据库中的数据进行比较:



HI

I need to get User Name and Password values from client side on the code behind to compare it with data on the database :

<div class="container">
        <h1>Welcome</h1>

        <form class="form">
            <input type="text" placeholder="Username" />
            <input type="password" placeholder="Password"/>
            <button type="submit" id="login-button">Login</button>
        </form>
    </div>





可以帮助任何人!!



can any one help !!

推荐答案

发布时我的解决方案2,我没注意你想从客户端获取用户名和密码。事实上,这是一个坏主意,但解决方案1,如果这个想法一瞥就完全错过了重点;它会让你对它是如何工作毫无头绪。



首先,你应该明白密码不会存储在任何地方。你觉得这不可能吗?再想想。这个想法是:只存储密码的加密哈希函数。此功能不允许从功能结果中恢复密码,因此,无论在服务器部件(例如托管公司)上工作的人员有多少访问权限,都无法帮助他们了解客户的密码。您是否了解密码具有自己的价值,与密码保护数据的价值无关?请参阅: https://en.wikipedia.org/wiki/Cryptographic_hash_function [ ^ ]。



现在,如果是用户在客户端计算密码的哈希并将其发送到服务器部分,人们窃听邮件也无法弄清楚密码。但是,即使不知道它,也可以通过发送相同的哈希来伪造相同的密码。因此,除了加密哈希函数技术之外,还使用了HTTPS:

https://en.wikipedia .org / wiki / HTTPS [ ^ ],

https://en.wikipedia.org/wiki/Transport_Layer_Security [ ^ ]。



In转而,TLS基于对称加密公钥加密

https://en.wikipedia.org/wiki/Symmetric_cryptography [ ^ ],

https://en.wikipedia.org / wiki / Public_key_cryptography [ ^ ]。



如果了解它是如何工作的,您将了解它如何保护网站和用户免受密码或身份盗用,甚至是人们窃听所有通信并完全访问网站数据。



-SA
While posting my Solution 2, I did not pay attention that you want to "get username and password" from the client side. Indeed, this is a bad idea, but "Solution 1", giving a glimpse if the idea, totally misses the point; it leaves you clueless on how it really works.

First of all, you should understand that the passwords are not stored anywhere. Do you think its impossible? Think again. The idea is: only the cryptographic hash function of passwords is stored. This function does not allow to restore the password from the function result, so, no matter how much of access people working on the server part (say, hosting company) have, it won't help them to know customer's password. Do you understand that passwords have their own value, unrelated to the value of password-protected data? Please see: https://en.wikipedia.org/wiki/Cryptographic_hash_function[^].

Now, if a user calculates a password's hash in the client side and sends it to the server part, people eavesdropping the message also cannot figure out the password. But it's possible to fake the same password even without knowing it, by sending the same hash. So, on top of the cryptographic hash function technique, HTTPS is used:
https://en.wikipedia.org/wiki/HTTPS[^],
https://en.wikipedia.org/wiki/Transport_Layer_Security[^].

In turn, TLS is based on both symmetric cryptography and public-key cryptography:
https://en.wikipedia.org/wiki/Symmetric_cryptography[^],
https://en.wikipedia.org/wiki/Public_key_cryptography[^].

If you understand how it works, you will understand how it protects the site and the user from password or identity theft, even from the people eavesdropping all communications and having full access to the site data.

—SA


JavaScript值与C#值无关。 JavaScript在客户端工作,C#只能在服务器端工作。



您的表单可以用来向服务器端发送HTTP请求,实际上,这个是 form 元素的唯一基本功能。您编写的表单缺少按钮或输入元素上的 methodormmethod 属性和操作。请参阅:

https://developer.mozilla.org / en-US / docs / Web / HTML /元素/表单 [ ^ ],

https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms [ ^ ]。



如果你这样做它,指向 action 的页面指针将接收HTTP请求,其中提交的数据将以键值对的形式出现,其中键由定义name 你已写过的属性。



现在,正如你提到的C#,它可能意味着你要使用ASP.NET,这将是处理您的HTTP请求。这就是它的完成方式(在这个例子中,在Razor中): http://www.asp.net/web-pages/overview/ui,-layouts,-and-themes/4-working-with-forms [ ^ ]。



适用于所有非废话HTTP服务器的所有ASP.NET 视图引擎(。ASPX标记)和所有其他服务器端脚本模块几乎相似的访问表单数据的方法。从文档中了解您正在使用的内容。



向服务器端提交用户输入数据的另一种方法是Ajax: https://en.wikipedia.org/wiki/Ajax_(编程) [ ^ ]。



Ajax允许使用数据发送任何HTTP请求在JavaScript运行时动态计算并消除页面的完全重新加载,因为您可以使用从 HTTP响应通过Ajax接收的数据获取请求的数据并使用JavaScript直接操作当前页面的DOM。 />


-SA
JavaScript values have nothing to do with C# values. JavaScript works on the client side, and C# can only work on the server side.

Your form can be used to send HTTP request to the server side, actually, this is the only essential function of the form element. The form you wrote lacks the attributes methodormmethod attribute on a button or input elements) and action. Please see:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form[^],
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms[^].

If you do it, the page pointer to by action will receive HTTP request where the submitted data will come in key-value pairs, where the key is defined by the name attributes you already wrote.

Now, as you mentioned C#, it probably means that you want to use ASP.NET, which will handle your HTTP request. This is how it's done (in this example, in Razor): http://www.asp.net/web-pages/overview/ui,-layouts,-and-themes/4-working-with-forms[^].

All ASP.NET view engines (.ASPX markup) and all other server-side scripting module for all non-nonsense HTTP servers have pretty much similar means of accessing form data. Learn what you are using from its documentation.

Alternative way of submitting user-input data to the server side is Ajax: https://en.wikipedia.org/wiki/Ajax_(programming)[^].

Ajax allows to send any HTTP requests with data calculated during JavaScript runtime dynamically and eliminate full re-loading of the page, because you can just get requested data and directly manipulate current page's DOM with JavaScript, utilizing the data received via Ajax from HTTP response.

—SA


嗯,SA是绝对正确的。



回答你的问题是:不,你不能。

JavaScript在客户端和C#在服务器端工作。



如果你想将这些值与有价值的数据库,你实际上需要C#的力量。你无法使用JavaScript完成它。

虽然使用JavaScript你可以对服务器进行AJAX调用,但该服务器只不过是用C#编写的代码片段。因此,您将调用C#代码。



您可以使用JS执行一些客户端验证,但在您的情况下,您需要使用C#进行比较那些带有数据库值的值。



-KR
Well, SA is absolutely right.

And answer to your question is : No, you can't.
JavaScript works on client-side and C# on server-side.

If you want to compare those values with the database valued, you'd actually need the C# power. There's no way you can get it done using JavaScript only.
Though, using JavaScript you can make a AJAX call to the server, but that server is nothing but the piece of code that is written in the C#. Hence, you'd be making a call to C# code.

You can perform some client-side validations using JS but in your case you'd need C# to compare those values with the database values.

-KR


这篇关于Javascript和C#值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆