讲解:5ENT1070、Aims、SQL、SQLR|Python

5ENT1070 – Web ServicesUser Authentication in WCFAims• Add a new table to your MDF file to store User Info• Modify your previous WCF solution to allow for the registration of users• Modify further to enable verification of users before other database requests are made• Test it works and submit your WCF solution on StudyNet. Please include screen shots of theTest Client as further evidence!Task 1 – Add a ‘Users’ table to your database• Copy your previous WCF solution to Desktop and open with Visual Studio.o This should be the WCF solution from the lab “Databases with WCF”.• The first thing we need to do is create a new table for storing User Information.o In your Visual Studio Window, go to your Server Explorer (Usually located as a sidetab on the left hand side).o Open the connection by expanding the database (When open you will see a littlegreen connected icon).o Right click on the database and select New Query.o Write a query to CREATE a new table that contains columns for ID, User Name, UserPassword, First Name, Last Name, and Permissions.▪ CAUTION: Do not call any column password, as this is a keyword in SQL andwill cause issues.▪ Also do not put spaces in column names as this will cause an error.▪ Keywords like CREATE are not case sensitive so do not have to be upper case▪ Table and variable names ARE case sensitive, so how you write them in yourCREATE query is how they must be written anywhere afterwards.o NOTE: the use of variable type VARBINARY(64) which is a byte array of 64 bytes(Byte[64]). This is because a 512-bit SHA3 algorithm will output 64 bytes of data (8bits in a byte therefore 512/8=64).o Once executed, check the table exists by refreshing your database in the ServerExplorer to see if it appears in the Tables folder.Task 2 – Add User Registration capability to WCF• Now the next thing to do is create a new DataContract which will represent a User object.o Open your IService1.cs file and after the close bracket for your public interfaceIService1, write a [DataContract] with a class called User. This class should reflectvariables you have in your database, except for password, which is a varbinary inyour table but must be a string here, as shown below:▪ NOTE: Don’t forget to add [DataMember] to each of your variables as shownbelow!• Next we need to add an [OperationContract] to the WCF which allows you to register a user.This is done inside the public interface IService1 declaration.o This contract will be called RegisterUser and return an int, with the parameter of aUser object:o Now open your Service1.svc.cs file to write this OperationContract logic.o This is where we need to install a library package to your WCF from NuGet, whichwill give you the ability to use SHA3 to hash passwords:▪ Click on the Tools tab in Visual Studio.▪ Go to NuGet Package Manager -> Manage NuGet Packages for Solution…▪ Click on the Browse tab and search for SHA3, you should get the optionshown below (the latest stable version may be different, please use thelatest available):▪ Make sure your project is checked on the right hand side and click the Installbutton in the bottom right corner. This will download the libraries and addthem to your project.▪ Finally, in your Service1.svc.cs file declare a global declaration ofSHA3.SHA3Managed using a 512-bit size:o Now we can write our OperationContract for registerUser and implement SHA3hashing during the SQL INSERT:▪ Open your Service1.svc.cs and create a new method as shown below:▪ Don’t worry if you see an error, the method isn’t finished yet!▪ Next we need to add functionality that will allow us to connect to an SQLDatabase and run an INSERT query to代写5ENT1070作业、代做Aims留学生作业、SQL程序语言作业调试、SQL课程作业代写 帮做R语言编程|代写Pyt our Users table, with the data withinthe User object called ‘u’:▪ Notice the use of sha3Provider, which will take the string value ofu.Password, convert it into a Byte array, then hash it and put the hasheddata into the SqlCommand.▪ This registerUser method will return an int of how many rows were affectedby this query (Should be 1 if successful), otherwise -1 if an exceptionoccurred.o While this file is still open, run the solution and try adding a user with the WCF TestClient.▪ NOTE: ID value will not be used in this registerUser method, so no need toenter it in the Test Client.o Enter at least one user like this with permission of 0 (Zero), as this will be admin(remember the password!).o Verify by checking your database table via Server Explorer.o Password data now shows in the database as a hexadecimal representation ofhashed data, not a plaintext password! Using SHA3, the correct password willALWAYS produce exactly the same hash data.Task 3 – Private User Verification• Next we need to be able to verify if a user is registered.o Stop the program and open your Service1.svc.cs file.o Write a new method called vaidateUser which returns an int and uses stringusername and password, and also an OUT function with a User Object:▪ Using the out feature means we can send out objects as well as return somevalue. Here we can return a number to indicate success or not, while alsospitting out a User object.▪ Making it private means that only this class can use this method.o Inside this method you need to add another SqlConnection, as you have before. Thistime it will do a SELECT function with the Users table:▪ SELECT will look for username and password as a hash in the Users table.▪ This method will return 1 if the user exists, 0 if they do not and -1 if anexception occurs.o Next we need to add a global User object, for our OUT to update later…o We can’t test this method using the Test Client directly, because it is a privatemethod, so we need to use it in one of our OperationContracts to check it works:▪ In your Service1.svc.cs file, find your GetData method you wrote in theprevious lab and add two parameters to the method declaration, stringAdminName and string AdminPass.▪ You will also need to make this change in your IService1.cs file.o Next we need to add an if statement around ALL of the method contents, so that thelogic of this method will only run IF a valid users credentials are given:o This will only return data IF the user exists, but it will not check the userspermissions. We can modify the IF statement to check this also:o Adding this will check if the user exists (== 1), then will check if permission is zero(admin) or (||) is equal to the house id being requested.o Now we can run this and test with the Test Client.▪ NOTE: Check your Houses table to make sure you are getting data for ahouse id that exists. ▪ Also if you use a username and password for a user who is not permission 0,null will be returned IF the user permission does not match the requestedhouse id.Task 4 – Add Validation to Other Operation ContractsUse the steps from Task 3 to replicate the use of the validateUser method in other methods youhave. You are trying to prevent:• Unauthorised registration of users (If any user can register themselves as admin there is nosecurity!). This is why I asked you to register at least one admin permission before protectingthe registration function. If you forget a password, you will have to temporarily commentout your code that checks credentials, in order to register a new admin, before reinstatingthe code again.• Unauthorised update of device data (verify permission before update).转自:http://www.6daixie.com/contents/15/5039.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 215,723评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,003评论 3 391
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,512评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,825评论 1 290
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,874评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,841评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,812评论 3 416
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,582评论 0 271
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,033评论 1 308
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,309评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,450评论 1 345
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,158评论 5 341
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,789评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,409评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,609评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,440评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,357评论 2 352

推荐阅读更多精彩内容

  • By clicking to agree to this Schedule 2, which is hereby ...
    qaz0622阅读 1,447评论 0 2
  • 欢迎关注飞飞国内游原创游记之苏州。 江南水乡,曼妙多姿,苏州就如那古典儒雅的抚琴女子。幽寂古巷,傍河古楼,透漏着古...
    心向北飞阅读 234评论 3 0
  • 后来被自己所想的罪恶感与卑微所蚕食殆尽,我觉的自己很辣鸡没骨气,又很坏做了很多错事,每天这样我都像泄气的气球,想鼓...
    读书文化人阅读 310评论 0 0
  • 能否借力 昨天上午开完会后,9点多,带领福星和大勇去杨集进行机房整治,一直到12:10.下午2:30到办公室,后来...
    雪木912阅读 175评论 0 1
  • 我的同桌叫小红,小红平时不爱说话,但是她喜欢助人为乐,每次上课她都认真听讲,全神贯注地听老师讲课,每次我遇到不会的...
    苡前苡后阅读 221评论 0 0